CData Python Connector for QuickBooks Online

Build 22.0.8678

データのクエリ

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

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

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

engine = create_engine("quickbooksonline:///?InitiateOAuth=GETANDREFRESH;")
factory = sessionmaker(bind=engine)
session = factory()
for instance in session.query(Customers).filter_by(GivenName="Cook, Brian"):
	print("Id: ", instance.Id)
	print("Id: ", instance.Id)
	print("GivenName: ", instance.GivenName)
	print("---------")

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

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

Customers_table = Customers.metadata.tables["Customers"]
for instance in session.execute(Customers_table.select().where(Customers_table.c.GivenName == "Cook, Brian")):
	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.8678