> -----Original Message----- > From: sqlalchemy@googlegroups.com > [mailto:sqlalch...@googlegroups.com] On Behalf Of darkblueB > Sent: 17 August 2009 06:31 > To: sqlalchemy > Subject: [sqlalchemy] new questions > > > Hi- > I have just read a lot and gone through some exercises, but am at an > early stage here.. > Two questions: > > 1) I have an existing database, and want to use sa to work with it.. > so "reflect" seems like what I want. I have loaded up the database > successfully - sqlite - not with reflect(), but instead with named > tables and autoload=true. > > Now I am reading about declarative base class.. is a reflect/ > autoload approach preemptive of declarative? do I have to make > mappers? there are a number of foreign key relationships, declared in > the db.. how do I find out more about which ones are being > instantiated for me? > > 2) Session vs connect.. from my limited experience, conn = > engine.connect() seems natural and all I need. I am reading this intro > material and they are going on at length with Session. Is Session > really necessary? so much more desirable? > > I am really looking for an expedient use of sa, I dont think I will > get deeply into this.. pragmatic! > thanks in advance > -Brian >
Hi, In answer to your first question, the declarative extension is pretty flexible. You can still use autoload to get the table definitions, and then explicitly add anything that the autoload doesn't pick up. There is an example at http://www.sqlalchemy.org/docs/05/reference/ext/declarative.html#table-c onfiguration Once your declarative class has been created, you can access the underlying table object as "YourMappedClass.__table__". This table should have a foreign_keys property which lists all the forgein keys, so you can see whether they have been detected correctly. As for your second question, this is mostly about the difference between the "SQL Expression Language" layer of SQLAlchemy, which generally works with engines and connections, and the "ORM" layer, which normally works with the Session. The description at http://www.sqlalchemy.org/docs/05/session.html#what-does-the-session-do is probably a reasonable description of why you might want to use a Session. If you are only ever reading data from the database, and you don't want or need to build object relationships on top of your SQL data, you can easily get away with the SQL Expression Language layer and not need the ORM. However, if you need to do much more than basic manipulation of the data, the ORM can make your life much easier. Hope that helps, Simon --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---