forked from orbit-oss/flask
Fixed small mistake in sqlalchemy pattern
This commit is contained in:
parent
80b2689335
commit
69e419e020
1 changed files with 3 additions and 3 deletions
|
|
@ -42,7 +42,7 @@ Here the example `database.py` module for your application::
|
||||||
engine = create_engine('sqlite:////tmp/test.db', convert_unicode=True)
|
engine = create_engine('sqlite:////tmp/test.db', convert_unicode=True)
|
||||||
db_session = scoped_session(sessionmaker(autocommit=False,
|
db_session = scoped_session(sessionmaker(autocommit=False,
|
||||||
autoflush=False,
|
autoflush=False,
|
||||||
bind=engine))
|
bind=engine))
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
Base.query = db_session.query_property()
|
Base.query = db_session.query_property()
|
||||||
|
|
||||||
|
|
@ -130,7 +130,7 @@ Here is an example `database.py` module for your application::
|
||||||
metadata = MetaData()
|
metadata = MetaData()
|
||||||
db_session = scoped_session(sessionmaker(autocommit=False,
|
db_session = scoped_session(sessionmaker(autocommit=False,
|
||||||
autoflush=False,
|
autoflush=False,
|
||||||
bind=engine))
|
bind=engine))
|
||||||
def init_db():
|
def init_db():
|
||||||
metadata.create_all(bind=engine)
|
metadata.create_all(bind=engine)
|
||||||
|
|
||||||
|
|
@ -189,7 +189,7 @@ To insert data you can use the `insert` method. We have to get a
|
||||||
connection first so that we can use a transaction:
|
connection first so that we can use a transaction:
|
||||||
|
|
||||||
>>> con = engine.connect()
|
>>> con = engine.connect()
|
||||||
>>> con.execute(users.insert(name='admin', email='admin@localhost'))
|
>>> con.execute(users.insert(), name='admin', email='admin@localhost')
|
||||||
|
|
||||||
SQLAlchemy will automatically commit for us.
|
SQLAlchemy will automatically commit for us.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue