Re: [sqlalchemy] Modifying records across multiple modules?

2016-02-04 Thread Alex Hall
Yes, I'm using Declarative. I was following a great tutorial, then realized it was way out of date. The one recommended on the forum I found said to use Declarative, so I did. In DBInterface, I have this little function: def getAllTables(): return base.metadata.tables #end def getAllTables I

Re: [sqlalchemy] Modifying records across multiple modules?

2016-02-04 Thread Simon King
SQLAlchemy has 2 main layers, the "Core" layer which deals with mostly database-level constructs, such as Tables, and the ORM layer, which is built on top of Core. With the ORM, you map your own classes onto the lower-level Tables, then work with instances of those classes. You appear to be using

Re: [sqlalchemy] Modifying records across multiple modules?

2016-02-04 Thread Alex Hall
Oh! Okay, I think I get you now. The only reason I pass a list of table objects is that I need the name, and I thought I needed the table to query. If I can obtain the table name from the class (.__tablename__), then this should work, with no need to mess with table objects at all. I'll try it.

Re: [sqlalchemy] Modifying records across multiple modules?

2016-02-04 Thread Alex Hall
I was re-reading your email, and realized I forgot to answer something (sorry, it's early here). It looks like I am indeed passing the table to session.query, which works, but then I'm trying to change attributes of the table, which doesn't (of course). Could I do this? #DBDefinitions.py import

Re: [sqlalchemy] Modifying records across multiple modules?

2016-02-04 Thread Simon King
You need to use the class when querying the database. SQLAlchemy will then return an instance of that class for each matching row: customer = session.query(Customer).filter_by(name=u'Powersports Etc').first() customer.name = u'New Name' session.flush() The getAllClasses function I showed

Re: [sqlalchemy] Modifying records across multiple modules?

2016-02-04 Thread Simon King
getAllTables is returning Core Table objects. I suppose you could have a similar function which returns all mapped classes, something like this: def getAllClasses(): return base.__subclasses__() (If your class hierarchy is more complicated you'd need a more sophisticated function there)

Re: [sqlalchemy] Modifying records across multiple modules?

2016-02-04 Thread Alex Hall
This is where sqlalchemy gets murky for me. If I return all classes, I'm not returning all *instances* of those classes. How, then, would I update a given customer's record? The objects (c1 and c2, for instance) were instantiated elsewhere, and my GUIManager module has no knowledge of them. More

Re: [sqlalchemy] Modifying records across multiple modules?

2016-02-03 Thread Simon King
OK, so you’re not actually getting Customer objects back from your query. What does your call to session.query() look like? For this to work, it really ought to be something like “session.query(Customer)”. I suspect you are doing something like “session.query(Customer.id, Customer.name, …)”

Re: [sqlalchemy] Modifying records across multiple modules?

2016-02-03 Thread Simon King
On Wed, Feb 3, 2016 at 3:54 PM, Alex Hall wrote: > Hello list, > I'm new to SQLAlchemy, but not to Python. I have an application that's > coming together, and relies on SQLAlchemy to talk to a database for > many of the app's functions. Listing tables, listing records,