Charles Duffy wrote:
> When creating tables via Table() calls, it's obvious how to indicate
> which engine should be used. With ActiveMapper, on the other hand,
> it's... less obvious. I've tried assuming that a reference to the
> first
> engine I created would be stored in the thread-local storage area if I
> have the threadlocal module imported, but that doesn't appear to be
> the
> case. Any hints?
Two ways to do this. Here is your code refactored to show both ways:
### EXAMPLE ONE: specify engine on the class itself ###
import sqlalchemy.mods.threadlocal
from sqlalchemy import *
from sqlalchemy.ext.activemapper import *
engine = create_engine('sqlite:///:memory:')
class Foo(ActiveMapper):
class mapping:
__table__ = 'foo_tbl'
__engine__ = engine
foo_id = column(Integer, primary_key=True)
foo_text = column(String(30))
f = Foo(foo_text='test').flush()
### EXAMPLE TWO: use the metadata on the activemapper module ###
import sqlalchemy.mods.threadlocal
from sqlalchemy import *
from sqlalchemy.ext.activemapper import *
import sqlalchemy.ext.activemapper as activemapper
engine = create_engine('sqlite:///:memory:')
activemapper.metadata.connect(engine)
class Foo(ActiveMapper):
class mapping:
__table__ = 'foo_tbl'
foo_id = column(Integer, primary_key=True)
foo_text = column(String(30))
f = Foo(foo_text='test').flush()
I hope this helps. Good luck!
--
Jonathan LaCour
http://cleverdevil.org
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users