mirror of
https://github.com/skylanix/MamieHenriette.git
synced 2026-02-06 14:50:34 +01:00
extraction du modul database et creation de page vide
This commit is contained in:
12
database/__init__.py
Normal file
12
database/__init__.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from sqlalchemy.sql import text
|
||||
from webapp import webapp
|
||||
|
||||
webapp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
|
||||
db = SQLAlchemy(webapp)
|
||||
|
||||
with webapp.app_context():
|
||||
with open('database/schema.sql', 'r') as f:
|
||||
sql_script = f.read()
|
||||
db.session.execute(text(sql_script))
|
||||
db.session.commit()
|
||||
9
database/message.py
Normal file
9
database/message.py
Normal file
@@ -0,0 +1,9 @@
|
||||
# from webapp import db
|
||||
from database import db
|
||||
|
||||
class Message(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
enable = db.Column(db.Boolean, default=False)
|
||||
text = db.Column(db.String(200))
|
||||
# en seconde
|
||||
periodicity = db.Column(db.Integer)
|
||||
6
database/schema.sql
Normal file
6
database/schema.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
CREATE TABLE IF NOT EXISTS `message` (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`enable` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
`text` VARCHAR(256) NULL,
|
||||
periodicity INTEGER NULL
|
||||
);
|
||||
Reference in New Issue
Block a user