Exemplo n.º 1
0
    # Make sure that the db is initialized only once!
    db = SQLAlchemy(metadata=MetaData(naming_convention=naming_convention))
    API.db = db
    # if "mysql" in db.session.bind.dialect.name:
    #     # This is nessary for the QUERY below to read the changes make by other processes.
    #     logging.info( "SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED" )
    #     db.session.execute( "SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED" )

    db.get_model = get_model
    db.get_model_by_tablename = get_model_by_tablename
    # temp. vars
    # Column          = db.Column
    # relationship    = ORM.relationship
    # Model           = db.Model
    db.MEDIUMBLOB = types._Binary
    db.LONGBLOB = types._Binary
    db.MEDIUMTEXT = MEDIUMTEXT
    db.LONGTEXT = LONGTEXT
    db.MEDIUMCLOB = MEDIUMTEXT
    db.LONGCLOB = LONGTEXT
    thread_db = {threading.currentThread().name: db}


def destroyDatabaseObject(obj):
    global db, thread_db
    if db == obj:
        # delete the master, so everything goes !
        for name, tdb in thread_db.items():
            if tdb is not db:
                del tdb
Exemplo n.º 2
0

# MainThread db
db = None
if db is None:
    # Make sure that the db is initialized only once!
    db = SQLAlchemy(metadata=MetaData(naming_convention=naming_convention))
    API.db = db
    db.get_model = get_model
    db.get_model_by_tablename = get_model_by_tablename
    # temp. vars
    # Column          = db.Column
    # relationship    = ORM.relationship
    # Model           = db.Model
    db.MEDIUMBLOB = sqlalchemy.types._Binary
    db.LONGBLOB = sqlalchemy.types._Binary
    db.MEDIUMTEXT = sqlalchemy.types.TEXT
    db.LONGTEXT = sqlalchemy.types.TEXT
    db.MEDIUMCLOB = sqlalchemy.types.TEXT
    db.LONGCLOB = sqlalchemy.types.TEXT
    thread_db = {threading.currentThread().name: db}


def getDataBase(app=None):
    if has_request_context():
        return db

    if threading.currentThread().name in thread_db:
        return thread_db[threading.currentThread().name]

    logging.warning("Create new DB session for application context")