diff --git a/slaeforms/app.py b/slaeforms/app.py index 987dcfb..bba8b89 100644 --- a/slaeforms/app.py +++ b/slaeforms/app.py @@ -5,27 +5,29 @@ from flask_sqlalchemy import SQLAlchemy from sqlalchemy.orm import DeclarativeBase from sqlalchemy import Integer, String from sqlalchemy.orm import Mapped, mapped_column +from datetime import datetime - +#create the app app = Flask(__name__) -# configure the SQLite database, relative to the app instance folder +# configure the database, give it a path (it will be in the instances folder) app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///database.db" -# initialize the app with the extension -db.init_app(app) -data = {} +db = SQLAlchemy(app) -class Base(DeclarativeBase): - pass +# create the model for the response table +class Response(db.Model): + id = db.Column(db.Integer, primary_key=True) + likert_result = db.Column(db.Integer, nullable=False) + notes = db.Column(db.String(200)) + date_created = db.Column(db.DateTime, default=datetime.utcnow) -class User(db.Model): - id: Mapped[int] = mapped_column(primary_key=True) - username: Mapped[str] = mapped_column(unique=True) - email: Mapped[str] + def __repr__(self) -> str: + return "" % self.id +# create the table (existing tables are not overwritten) with app.app_context(): db.create_all() + print("Table created") -db = SQLAlchemy(model_class=Base) @app.route("/", methods=["GET", "POST"]) def testpage(): diff --git a/slaeforms/database.db b/slaeforms/database.db deleted file mode 100644 index b111f42..0000000 Binary files a/slaeforms/database.db and /dev/null differ diff --git a/slaeforms/db.py b/slaeforms/db.py deleted file mode 100644 index ed0fdf3..0000000 --- a/slaeforms/db.py +++ /dev/null @@ -1,9 +0,0 @@ -import click -from flask import current_app, g -from flask_sqlalchemy import SQLAlchemy -from sqlalchemy.orm import DeclarativeBase - -class Base(DeclarativeBase): - pass - -db = SQLAlchemy(model_class=Base) \ No newline at end of file