|
|
@ -49,15 +49,21 @@ def close_database(exception): |
|
|
|
top.sqlite_db.close() |
|
|
|
top.sqlite_db.close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.cli.command() |
|
|
|
def init_db(): |
|
|
|
def initdb(): |
|
|
|
"""Initializes the database.""" |
|
|
|
"""Creates the database tables.""" |
|
|
|
|
|
|
|
db = get_db() |
|
|
|
db = get_db() |
|
|
|
with app.open_resource('schema.sql', mode='r') as f: |
|
|
|
with app.open_resource('schema.sql', mode='r') as f: |
|
|
|
db.cursor().executescript(f.read()) |
|
|
|
db.cursor().executescript(f.read()) |
|
|
|
db.commit() |
|
|
|
db.commit() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.cli.command('initdb') |
|
|
|
|
|
|
|
def initdb_command(): |
|
|
|
|
|
|
|
"""Creates the database tables.""" |
|
|
|
|
|
|
|
init_db() |
|
|
|
|
|
|
|
print('Initialized the database.') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def query_db(query, args=(), one=False): |
|
|
|
def query_db(query, args=(), one=False): |
|
|
|
"""Queries the database and returns a list of dictionaries.""" |
|
|
|
"""Queries the database and returns a list of dictionaries.""" |
|
|
|
cur = get_db().execute(query, args) |
|
|
|
cur = get_db().execute(query, args) |
|
|
|