def __init__(self, db_url, db_schema, **kwargs): self.engine = create_engine(db_url) Base.metadata.bind = self.engine DBSession.configure(bind=self.engine) self.models = Models(Base, db_schema) self.query = Query(self.models, DBSession) self.persen_denda = 'persen_denda' in kwargs and \ kwargs['persen_denda'] or 0
from sqlalchemy import create_engine from base_models import ( Base, DBSession, ) from models import Models from query import Reversal from .conf import ( db_url, transaction_schema, area_schema, iso_schema, ) engine = create_engine(db_url) Base.metadata.bind = engine DBSession.configure(bind=engine) models = Models(Base, transaction_schema, area_schema, iso_schema) class ReversalByQuery(Reversal): def __init__(self, invoice_id_raw): Reversal.__init__(self, models, DBSession, invoice_id_raw) def set_unpaid(self): Reversal.set_unpaid(self) self.DBSession.commit()
Models, ) from conf import ( db_url, other_db_url, db_pool_size, db_max_overflow, host, ) engine = create_engine( db_url, pool_size=db_pool_size, max_overflow=db_max_overflow) Base.metadata.bind = engine DBSession.configure(bind=engine) models = Models(Base) query = Query(models, DBSession) other_engine = create_engine( other_db_url, pool_size=db_pool_size, max_overflow=db_max_overflow) OtherBase = declarative_base() OtherBase.metadata.bind = other_engine session_factory = sessionmaker() OtherDBSession = scoped_session(session_factory) OtherDBSession.configure(bind=other_engine) other_models = OtherModels(OtherBase) def create_ntp():