Database is there and gets initialized
This commit is contained in:
parent
4fc6765b1d
commit
d023307ccd
@ -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 "<Task %r>" % 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():
|
||||
|
Binary file not shown.
@ -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)
|
Loading…
Reference in New Issue
Block a user