Skip to content
Myr

Update sqlite3.rst

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

authored by Mieszko · committed by Mieszko · parent 13bd858 · 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/sqlite3.rst+3 added-3 removed
2 unmodified lines
3Using SQLite 3 with Flask4=========================56In Flask you can easily implement the opening of database connections on 7demand, closing them when the context dies (usually at the end of the 7demand and closing them when the context dies (usually at the end of the 8request).910Here is a simple example of how you can use SQLite 3 with Flask::11
70 unmodified lines
82Or even simpler::8384 db.row_factory = sqlite3.Row8586Additionally it is a good idea to provide a query function that combines86Additionally, it is a good idea to provide a query function that combines87getting the cursor, executing and fetching the results::88 89 def query_db(query, args=(), one=False):90 cur = get_db().execute(query, args)
39 unmodified lines
130 with app.open_resource('schema.sql', mode='r') as f:131 db.cursor().executescript(f.read())132 db.commit()133134You can then create such a database from the python shell:134You can then create such a database from the Python shell:135136>>> from yourapplication import init_db137>>> init_db()