CData Python Connector for FreshBooks

Build 20.0.7587

Updating Data with Sessions

Establishing a Session

After a mapping class is defined and a connection is established, the session is used to modify data in the available tables. The session is initially obtained by performing the below:

engine = create_engine("freshbooks:///?InitiateOAuth=GETANDREFRESH;OAuthClientId=MyClientId;OAuthClientSecret=MyClientSecret;CallbackURL=http://localhost:33333")
factory = sessionmaker(bind=engine)
session = factory()

Insert

First, define an instance of the mapped class, then add it to the active session. Call "commit()" on the session to push all added instances as inserted rows.

new_rec = Clients(Id="20050", Email="Jon Doe", Username="John")
session.add(new_rec)
session.commit()

Update

First, fetch the desired records with a filtered query. Then, modify the values of their fields and call "commit()" to update any records modified in this way.

modded_rec = session.query(Clients).filter_by(Id="20050").first()
modded_rec.Email = "Jon Doe"
modded_rec.Username = "John"
session.commit()

Delete

First, fetch the desired records with a filtered query, then delete with the session. Call "commit()" to perform the delete operation with the provided rows.

removed_rec = session.query(Clients).filter_by(Id="20050").first()
session.delete(removed_rec)
session.commit()

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