CData Python Connector for SuiteCRM

Build 22.0.8462

Querying Data

After connecting with the steps in Connecting, and reflecting some of the metadata with one of the methods in Reflecting Metadata, you can query data using a session object.

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("suitecrm:///?URL=http://mySuiteCRM.com;User=myUser;Password=myPassword;")
factory = sessionmaker(bind=engine)
session = factory()
for instance in session.query(Accounts).filter_by(Industry="Manufacturing"):
	print("Id: ", instance.Id)
	print("Name: ", instance.Name)
	print("Industry: ", instance.Industry)
	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 is just as viable:

Accounts_table = Accounts.metadata.tables["Accounts"]
for instance in session.execute(Accounts_table.select().where(Accounts_table.c.Industry == "Manufacturing")):
	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.8462