From 3b22586890425c8b8e555bce649649228b26c02b Mon Sep 17 00:00:00 2001 From: Mitsuo Tokumori Date: Sun, 29 Oct 2023 14:28:43 -0500 Subject: Add students blueprint using psycopg --- ustayml/db.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'ustayml/db.py') 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') -- cgit v1.2.3