CData Python Connector for Zoho Books

Build 22.0.8479

データのクエリ

接続 の手順で接続後、メタデータの反映 内のメソッドの1つを使ってメタデータの一部を反映したら、セッションオブジェクトを使用してデータをクエリできます。

query メソッドを使用したデータのクエリ

マッピングクラスが用意されている場合は、セッションオブジェクトと併用してデータソースをクエリします。エンジンをセッションにバインドしたら、以下のように、マッピングクラスをセッションのクエリメソッドに提供するだけです。

engine = create_engine("zohobooks:///?InitiateOAuth=GETANDREFRESH;OrganizationId=YourOrganizationId;AccountsServer=YourAccountServerURL")
factory = sessionmaker(bind=engine)
session = factory()
for instance in session.query(INVOICES).filter_by(CustomerName="NewTech Industries"):
	print("Id: ", instance.Id)
	print("InvoiceId: ", instance.InvoiceId)
	print("InvoiceNumber: ", instance.InvoiceNumber)
	print("---------")

execute メソッドを使用したデータのクエリ

別の方法として、セッションオブジェクトは、適切なテーブルオブジェクトと一緒にexecute() メソッドを使用してクエリを実行することもできます。アクティブなセッションがあると仮定すると、以下は同様に実行可能です。

INVOICES_table = INVOICES.metadata.tables["INVOICES"]
for instance in session.execute(INVOICES_table.select().where(INVOICES_table.c.CustomerName == "NewTech Industries")):
	print("Id: ", instance.Id)
	print("FullName: ", instance.Name)
	print("City: ", instance.BillingCity)
	print("---------")

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8479