1import sqlite3
2
3import click
4from flask import current_app, g
5from flask.cli import with_appcontext
6
7
8def get_db():
9 if 'db' not in g:
10 g.db = sqlite3.connect(
11 current_app.config['DATABASE'],
12 detect_types=sqlite3.PARSE_DECLTYPES
13 )
14 g.db.row_factory = sqlite3.Row
15
16 return g.db
17
18
19def close_db(e=None):
20 db = g.pop('db', None)
21
22 if db is not None:
23 db.close()
24