I find it strange that people do not use dependency injection to manage their use of SQLAlchemy. According to the docs, one needs a reference to the table to perform db operations like inserts, but one only gets a reference to the table after it is created!
That means the db connection, db operations and table declarations must be done in the same file:
>>> from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
>>> conn = engine.connect()
>>> metadata = MetaData()
>>> users = Table('users', metadata,
... Column('id', Integer, primary_key=True),
... Column('name', String),
... Column('fullname', String),
... )
>>> ins = users.insert()
>>> result = conn.execute(ins)
According to the snippet above, one needs the conn connection object, the users table object and the ins expression object to perform a complete transaction with the database. Unless some form of dependency injection is used, all three must be in the same file.
How have people structured their code to make this manageable?
Tableobjects in different module or even package and import it, why they should be in the same file?