Esempio n. 1
0
    def __init__(self, db, autocommit=False, autoflush=True, **options):
        #: The application that this session belongs to.
        self.app = app = db.get_app()
        track_modifications = app.config['SQLALCHEMY_TRACK_MODIFICATIONS']
        bind = options.pop('bind', None) or db.engine
        binds = options.pop('binds', db.get_binds(app))

        if track_modifications is None or track_modifications:
            _SessionSignalEvents.register(self)

        XRaySession.__init__(self,
                             autocommit=autocommit,
                             autoflush=autoflush,
                             bind=bind,
                             binds=binds,
                             **options)
Esempio n. 2
0
 def get_bind(self, mapper=None, clause=None):
     # mapper is None if someone tries to just get a connection
     if mapper is not None:
         info = getattr(mapper.mapped_table, 'info', {})
         bind_key = info.get('bind_key')
         if bind_key is not None:
             state = get_state(self.app)
             return state.db.get_engine(self.app, bind=bind_key)
     return XRaySession.get_bind(self, mapper, clause)
    def get_bind(self, mapper=None, clause=None):
        # mapper is None if someone tries to just get a connection
        if mapper is not None:
            # info = getattr(mapper.mapped_table, 'info', {})
            try:
                # SA >= 1.3
                persist_selectable = mapper.persist_selectable
            except AttributeError:
                # SA < 1.3
                persist_selectable = mapper.mapped_table

            info = getattr(persist_selectable, 'info', {})
            bind_key = info.get('bind_key')
            if bind_key is not None:
                state = get_state(self.app)
                return state.db.get_engine(self.app, bind=bind_key)
        return XRaySession.get_bind(self, mapper, clause)