CData Python Connector for Google Contacts

Build 22.0.8479

データのクエリ

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

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

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

engine = create_engine("googlecontacts:///?InitiateOAuth=GETANDREFRESH;")
factory = sessionmaker(bind=engine)
session = factory()
for instance in session.query([My Contacts]).filter_by(Id="c7782206569106794554"):
	print("Id: ", instance.Id)
	print("GivenName: ", instance.GivenName)
	print("HomeEmailAddresses: ", instance.HomeEmailAddresses)
	print("---------")

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

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

[My Contacts]_table = [My Contacts].metadata.tables["[My Contacts]"]
for instance in session.execute([My Contacts]_table.select().where([My Contacts]_table.c.Id == "c7782206569106794554")):
	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