Premier jet acces BDD

This commit is contained in:
Kepka Ludovic
2025-08-09 01:56:38 +02:00
parent 1b708bb10a
commit a23d906cc4
7 changed files with 34 additions and 10 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
__pycache__
instance

View File

@@ -4,5 +4,5 @@ python-dotenv==1.0.0
aiohttp>=3.7.4,<4
audioop-lts; python_version>='3.13'
flask==2.3.2
#flask-sqlalchemy==3.0.3
flask>=2.3.2
flask-sqlalchemy>=3.0.3

6
schema.sql Normal file
View 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
);

View File

@@ -1,11 +1,15 @@
from flask import Flask
# from flask_sqlalchemy import SQLAlchemy
# import os
# file_path = os.path.abspath(os.getcwd())+"/todo.db"
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.sql import text
webapp = Flask(__name__)
# app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+file_path
# db = SQLAlchemy(app)
webapp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
db = SQLAlchemy(webapp)
from webapp import routes
from webapp import routes
with webapp.app_context():
with open('schema.sql', 'r') as f:
sql_script = f.read()
db.session.execute(text(sql_script))
db.session.commit()

8
webapp/models.py Normal file
View File

@@ -0,0 +1,8 @@
from webapp 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)

View File

@@ -1,6 +1,10 @@
from flask import Flask, render_template
from webapp import webapp
from webapp import webapp, db
from webapp.models import Message
@webapp.route("/")
def index():
# message = Message(text="bla bla", periodicity = 3600)
# db.session.add(message)
# db.session.commit()
return render_template("index.html")

View File

@@ -21,6 +21,7 @@
<li><a href="/">Modération</a></li>
<li><a href="/">Messages</a></li>
<li><a href="/">Commandes</a></li>
<li><a href="/">Configuration</a></li>
</ul>
</nav>
</header>