diff options
| author | Mitsuo Tokumori <rtokumori@pucp.edu.pe> | 2023-10-29 14:28:43 -0500 |
|---|---|---|
| committer | Mitsuo Tokumori <rtokumori@pucp.edu.pe> | 2023-10-29 14:28:43 -0500 |
| commit | 3b22586890425c8b8e555bce649649228b26c02b (patch) | |
| tree | 63c9cdb40535ab9de998854a41523ecf36e728b6 /ustayml/db.py | |
| parent | 43f9d78f8c00e13732b809519f0529ac293fd5ab (diff) | |
Add students blueprint using psycopg
Diffstat (limited to 'ustayml/db.py')
| -rw-r--r-- | ustayml/db.py | 19 |
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') |
