CData Python Connector for Office 365 2019 - Online Help
Questions / Feedback?

Querying Data

CData Python Connector for Office 365 2019 - Build 19.0.7416

After connecting with the steps in Connecting, you can query data using a session object.

Model Data Using a Mapping Class

Declare a mapping class for the table you wish to model in the ORM. This is done using "sqlalchemy.ext.declarative.declarative_base". A known table in the data model is modeled either partially or completely as in the below example:
import sqlalchemy.ext.declarative.declarative_base
Base = declarative_base()
class Events(Base):
	__tablename__ = "Events"
	Id = Column(String, primary_key=True)
	Id = Column(String)
	location_displayName = Column(String)

Querying Data Using the Query Method

If the mapping class has been prepared, it is used alongside a session object to query the data source. After binding the engine to the session, simply provide the mapping class to the session's query method, as below:

engine = create_engine("office365:///?InitiateOAuth=GETANDREFRESH;OAuthClientId=MyApplicationId;OAuthClientSecret=MySecretKey;CallbackURL=http://localhost:33333;")
factory = sessionmaker(bind=engine)
session = factory()
for instance in session.query(Events).filter_by(Id="Jq74mCczmFXk1tC10GB"):
	print("Id: ", instance.Id)
	print("Id: ", instance.Id)
	print("location_displayName: ", instance.location_displayName)
	print("---------")

Querying Data Using the Execute Method

As an alternative, the session object can also run the query with the execute() method alongside the appropriate Table object. Assuming you have an active session, the below should be just as viable:

Events_table = Events.metadata.tables["Events"]
for instance in session.execute(Events_table.select().where(Events_table.c.Id == "Jq74mCczmFXk1tC10GB")):
	print("Id: ", instance.Id)
	print("FullName: ", instance.Name)
	print("City: ", instance.BillingCity)
	print("---------")

 
 
Copyright (c) 2020 CData Software, Inc. - All rights reserved.
Build 19.0.7416.0