On Sep 4, 2008, at 7:16 PM, Sam wrote:
>
> I woke up today and decided it was time to switch one of my simpler
> programs from sqlobject to sqlalchemy.
>
> I'm using reflection. After some googling I was able to find a way
> to insert:
> mp = mphones.insert().execute(word=word, mphone=phone)
>
> The above works okay.
>
> But I'd rather be able to do something like this:
> mp = mphones(word=word, mphone=phone)
> sess.add(mp)
>
> Unfortunately I couldn't make that work.
>
> Here's the setup code I'm using:
> from sqlalchemy import *
> from sqlalchemy.orm import sessionmaker
>
> engine = create_engine("postgres://postgres:[redacted]/mydb")
> meta = MetaData()
> meta.bind = engine
>
> Session = sessionmaker(bind=engine)
> sess = Session()
>
> mphones = Table('mphones', meta, autoload=True)
Table isnt going to cut it alone; you'd have to use mappers. Read
through the ORM tutorial and you'll get a sense of how to do that.
I'd recommend using declarative_base() to set things up which is what
the tutorial uses most of the way.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---