Skip to content
Myr

Fixed small mistake in sqlalchemy pattern

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by pinchsp · committed by pinchsp · parent 80b2689 · Browse files · 1 file+3 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+3 added−3 removed

  • other:+3 added−3 removed

1 file+3 added−3 removed

modified:docs/patterns/sqlalchemy.rst+3 added-3 removed
40 unmodified lines
4142 engine = create_engine('sqlite:////tmp/test.db', convert_unicode=True)43 db_session = scoped_session(sessionmaker(autocommit=False,44 autoflush=False,45 bind=engine)) 45 bind=engine))46 Base = declarative_base()47 Base.query = db_session.query_property()4849 def init_db():
79 unmodified lines
129 engine = create_engine('sqlite:////tmp/test.db', convert_unicode=True)130 metadata = MetaData()131 db_session = scoped_session(sessionmaker(autocommit=False,132 autoflush=False,133 bind=engine)) 133 bind=engine))134 def init_db():135 metadata.create_all(bind=engine)136137As for the declarative approach you need to close the session after
50 unmodified lines
188To insert data you can use the `insert` method. We have to get a189connection first so that we can use a transaction:190191>>> con = engine.connect()192>>> con.execute(users.insert(name='admin', email='admin@localhost'))192>>> con.execute(users.insert(), name='admin', email='admin@localhost')193194SQLAlchemy will automatically commit for us.195196To query your database, you use the engine directly or use a connection:
18 unmodified lines