forked from spaun299/profireader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_init.py
38 lines (34 loc) · 1.36 KB
/
db_init.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from config import ProductionDevelopmentConfig
from sqlalchemy import event
from utils.validators import validators
from flask import g
# db_session = g.db
# see this: http://flask.pocoo.org/docs/0.10/patterns/sqlalchemy/
# engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
# engine = create_engine(ProductionDevelopmentConfig.SQLALCHEMY_DATABASE_URI)
# db_session = scoped_session(sessionmaker(autocommit=False,
# autoflush=False,
# bind=engine))
# Base = declarative_base()
#
# # this event is called whenever an attribute
# # on a class is instrumented
# @event.listens_for(Base, 'attribute_instrument')
# def configure_listener(class_, key, inst):
# if not hasattr(inst.property, 'columns'):
# return
# # this event is called whenever a "set"
# # occurs on that instrumented attribute
#
# @event.listens_for(inst, "set", retval=True)
# def set_(instance, value, oldvalue, initiator):
# validator = validators.get(inst.property.columns[0].type.__class__)
# if validator:
# return validator(value)
# else:
# return value
#
# Base.query = db_session.query_property()