TG-35 : Connexion à la BDD et génération du modèle
This commit is contained in:
parent
228af15b44
commit
4d31f5fbe7
@ -5,6 +5,7 @@ from app.config import Config
|
||||
from flask import Flask, session
|
||||
from flask_restful import Api
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from sqlalchemy import MetaData
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.ext.automap import automap_base
|
||||
|
||||
@ -26,6 +27,7 @@ db = SQLAlchemy(app)
|
||||
Base = automap_base()
|
||||
engine = create_engine(app.config["SQLALCHEMY_DATABASE_URI"])
|
||||
Base.prepare(engine, reflect=True)
|
||||
meta = MetaData(engine, True)
|
||||
|
||||
# RestFul Flask
|
||||
api = Api(app)
|
||||
|
@ -1,9 +1,10 @@
|
||||
from app.core import Base
|
||||
from app.core import meta
|
||||
from sqlalchemy import Table
|
||||
|
||||
USER = Base.classes.user
|
||||
SETTINGS = Base.classes.settings
|
||||
HASHTABLE = Base.classes.hashtable
|
||||
GROUP = Base.classes.group
|
||||
GROUP_CONTENT = Base.classes.group_content
|
||||
PERIOD = Base.classes.period
|
||||
LIVRET = Base.classes.livret
|
||||
USER = Table('USER', meta, autoload=False)
|
||||
SETTINGS = Table('SETTINGS', meta, autoload=False)
|
||||
HASHTABLE = Table('HASHTABLE', meta, autoload=False)
|
||||
GROUP = Table('GROUP', meta, autoload=False)
|
||||
TUTORSHIP = Table('TUTORSHIP', meta, autoload=False)
|
||||
PERIOD = Table('PERIOD', meta, autoload=False)
|
||||
LIVRET = Table('LIVRET', meta, autoload=False)
|
||||
|
@ -4,11 +4,10 @@ import os
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
from app.config import Config
|
||||
from flask_script import Manager, Command
|
||||
from flask_script import prompt_bool
|
||||
|
||||
from app.config import Config
|
||||
|
||||
warnings.simplefilter('ignore')
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
@ -25,6 +24,7 @@ else:
|
||||
Config.configure_app(config="prod")
|
||||
|
||||
core = importlib.import_module("app.core")
|
||||
model = importlib.import_module("backend.app.model")
|
||||
|
||||
manager = Manager(core.app)
|
||||
manager.add_option("-d", "--debug",
|
||||
@ -59,7 +59,12 @@ class CheckDB(Command):
|
||||
|
||||
def run(self):
|
||||
print("List of parsed tables:")
|
||||
print(core.db.metadata.tables.keys())
|
||||
print(core.meta.tables.keys())
|
||||
query = model.SETTINGS.select()
|
||||
result = query.execute()
|
||||
print("\nSETTINGS content :")
|
||||
for res in result:
|
||||
print(res.key + " = " + res.value)
|
||||
|
||||
|
||||
manager.add_command('checkdb', CheckDB())
|
||||
|
Reference in New Issue
Block a user