summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstilbruch <stilbruch@protonail.com>2022-03-21 18:09:50 -0500
committerstilbruch <stilbruch@protonail.com>2022-03-21 18:10:43 -0500
commit681349db67bb828ab926b53734b44c50249d5f65 (patch)
treeba164fba3f86eca2576850b4aa3a882e9f2d2c7b
parente035041e1a02332694bfa692f62217e58d9fada6 (diff)
downloadStrengthy-681349db67bb828ab926b53734b44c50249d5f65.tar.xz
Strengthy-681349db67bb828ab926b53734b44c50249d5f65.zip
Setup basic database connections
-rw-r--r--.gitignore1
-rw-r--r--app/app.py9
-rw-r--r--app/database.py19
-rw-r--r--app/login.py0
-rw-r--r--app/routes.py8
-rwxr-xr-xsql/init_db.sh3
-rw-r--r--sql/schema.sql6
7 files changed, 42 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..98e6ef6
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.db
diff --git a/app/app.py b/app/app.py
index 2ea9126..7f105fd 100644
--- a/app/app.py
+++ b/app/app.py
@@ -1,7 +1,8 @@
-from flask import Flask, render_template
+from flask import Flask
+# Setup app before doing imports
app = Flask(__name__)
+app.config['TEMPLATES_AUTO_RELOAD'] = True
-@app.route("/", methods=["GET"])
-def index():
- return render_template('base/index.html')
+# Load routes
+import routes
diff --git a/app/database.py b/app/database.py
new file mode 100644
index 0000000..e23aa5d
--- /dev/null
+++ b/app/database.py
@@ -0,0 +1,19 @@
+import sqlite3
+from app import app
+from flask import g
+
+# constants
+DATABASE_FILE = "../strengthy.db"
+
+# Called when an "appcontext" is closed, usually a request is finished
+@app.teardown_appcontext
+def close_db_conn(exception):
+ db = getattr(g, '_database', None)
+ if db is not None:
+ db.close()
+
+def database_get():
+ db = getattr(g, '_database', None)
+ if db is None:
+ db = g._database = sqlite3.connect(DATABASE_FILE)
+ return db
diff --git a/app/login.py b/app/login.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/login.py
diff --git a/app/routes.py b/app/routes.py
new file mode 100644
index 0000000..c162b8d
--- /dev/null
+++ b/app/routes.py
@@ -0,0 +1,8 @@
+from app import app
+from database import database_get
+from flask import render_template
+
+@app.route("/", methods=["GET"])
+def index():
+ db = database_get()
+ return render_template('base/index.html')
diff --git a/sql/init_db.sh b/sql/init_db.sh
new file mode 100755
index 0000000..b48ab13
--- /dev/null
+++ b/sql/init_db.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+sqlite3 strenghty.db < sql/schema.sql
diff --git a/sql/schema.sql b/sql/schema.sql
new file mode 100644
index 0000000..e14d778
--- /dev/null
+++ b/sql/schema.sql
@@ -0,0 +1,6 @@
+-- User table
+CREATE TABLE user(
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ email TEXT NOT NULL,
+ hash TEXT NOT NULL
+);