Exemplo n.º 1
0
 def __init__(self):
     threading.Thread.__init__(self)
     self.daemon = True
     #Initializing database by opening MySQL-database
     #and creating a new SQLAlchemy session
     global engine
     engine = create_engine(SETTINGS.db_src, encoding='utf-8')
     self.__Session = sessionmaker(bind=engine, autoflush=True, transactional=True)()
     base_objects.create_tables(engine)
     self.start()
Exemplo n.º 2
0
#coding=utf8

from sqlalchemy.orm import  sessionmaker
from sqlalchemy import create_engine
from class_ import base_objects
from threading import Lock
import SETTINGS

#Initializing database by opening MySQL-database
#and creating a new SQLAlchemy session
engine = create_engine(SETTINGS.db_src, encoding='utf-8')
Session = sessionmaker(bind=engine, autoflush=True, transactional=True)
base_objects.create_tables(engine)
lock = Lock()

def add_all(objects):
    """
    Adds a list of objects into the database
    """
    lock.acquire()
    session = Session()
    session.add_all(objects)
    session.commit()
    session.close()
    lock.release()

def add(object):
    """
    Adds an object into the database
    """
    lock.acquire()