aboutsummaryrefslogtreecommitdiff
path: root/ustayml/db.py
diff options
context:
space:
mode:
Diffstat (limited to 'ustayml/db.py')
-rw-r--r--ustayml/db.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/ustayml/db.py b/ustayml/db.py
index eb4e8b4..8fb1ec9 100644
--- a/ustayml/db.py
+++ b/ustayml/db.py
@@ -1,4 +1,4 @@
-import sqlite3
+import psycopg
import click
from flask import current_app, g
@@ -10,12 +10,17 @@ def get_db():
sqlite3: https://docs.python.org/3/library/sqlite3.html
"""
if 'db' not in g:
- g.db = sqlite3.connect(
- current_app.config['DATABASE'],
- detect_types=sqlite3.PARSE_DECLTYPES
+ # g.db = sqlite3.connect(
+ # current_app.config['DATABASE'],
+ # detect_types=sqlite3.PARSE_DECLTYPES
+ # )
+ # # Return rows that behave like dicts
+ # g.db.row_factory = sqlite3.Row
+
+ g.db = psycopg.connect(
+ "dbname=ustayml user=mitsuo",
+ row_factory=psycopg.rows.dict_row
)
- # Return rows that behave like dicts
- g.db.row_factory = sqlite3.Row
return g.db
@@ -33,7 +38,7 @@ def init_db():
db = get_db()
with current_app.open_resource('schema.sql') as f:
- db.executescript(f.read().decode('utf8'))
+ db.execute(f.read().decode('utf8'))
@click.command('init-db')