Creates a context with an open SQLAlchemy session.
558916
def session(self):
        
        engine = self.engine
        connection = engine.connect()
        db_session = scoped_session(
            sessionmaker(autocommit=False, autoflush=True, bind=engine))
        yield db_session
        db_session.close()
        connection.close()
763117
def get_session():
    
    if hasattr(g, 'session'):
        return g.session
    sess = create_session(bind=current_app.config['DATABASE_ENGINE'])
    try:
        g.session = sess
    except RuntimeError:
        pass
    return sess
710204
def create_session(self, name=None):
        
        self.session = Session.create(self, name=name)
        return self.session
1315811
def create_db(app, appbuilder):
    
    from flask_appbuilder.models.sqla import Base

    _appbuilder = import_application(app, appbuilder)
    engine = _appbuilder.get_session.get_bind(mapper=None, clause=None)
    Base.metadata.create_all(engine)
    click.echo(click.style("DB objects created", fg="green"))
1350948
def shell_sqlalchemy(session: SqlalchemySession, backend: ShellBackend):
    
    namespace = {
        'session': session
    }
    namespace.update(backend.get_namespace())
    embed(user_ns=namespace, header=backend.header)
633009
def init_session(db_url=None, echo=False, engine=None, settings=None):
    
    if engine is None:
        engine = init_engine(db_url=db_url, echo=echo, settings=settings)
    return sessionmaker(bind=engine)
1075107
def attach_session(self):
        
        assert self.session is None
        root = self.find_root()
        session = self.Session(root)
        root.inject_context(session=session)
        return session
593524
def make_context(self, **kwargs):
        """"""
        self.check_schema()
        return Context(self.driver, self.config, **kwargs)
42061
def bootstrap(command, conf, vars):
    """"""

    # <websetup.bootstrap.before.auth
    from sqlalchemy.exc import IntegrityError
    try:
        u = model.User()
        u.user_name = 'manager'
        u.display_name = 'Example manager'
        u.email_address = 'manager@somedomain.com'
        u.password = 'managepass'
    
        model.DBSession.add(u)
    
        g = model.Group()
        g.group_name = 'managers'
        g.display_name = 'Managers Group'
    
        g.users.append(u)
    
        model.DBSession.add(g)
    
        p = model.Permission()
        p.permission_name = 'manage'
        p.description = 'This permission give an administrative right to the bearer'
        p.groups.append(g)
    
        model.DBSession.add(p)
    
        u1 = model.User()
        u1.user_name = 'editor'
        u1.display_name = 'Example editor'
        u1.email_address = 'editor@somedomain.com'
        u1.password = 'editpass'
    
        model.DBSession.add(u1)
        model.DBSession.flush()
        transaction.commit()
    except IntegrityError:
        print('Warning, there was a problem adding your auth data, it may have already been added:')
        import traceback
        print(traceback.format_exc())
        transaction.abort()
        print('Continuing with bootstrapping...')
635932
def db(self, connection_string=None):
        """"""

        connection_string = connection_string or self.settings["db"]

        if not hasattr(self, "_db_conns"):
            self._db_conns = {}
        if not connection_string in self._db_conns:
            self._db_conns[connection_string] = oz.sqlalchemy.session(connection_string=connection_string)

        return self._db_conns[connection_string]
1087314
def setup(self, app):
        ''' '''
        for other in app.plugins:
            if not isinstance(other, SQLAlchemyPlugin):
                continue
            if other.keyword == self.keyword:
                raise bottle.PluginError("Found another SQLAlchemy plugin with "\
                                  "conflicting settings (non-unique keyword).")
            elif other.name == self.name:
                self.name += '_%s' % self.keyword
        if self.create and not self.metadata:
            raise bottle.PluginError('Define metadata value to create database.')
142663
def create_exposed_session(self, session, key=None, context=None):
        
        # shiro ignores key and context parameters
        return DelegatingSession(self, SessionKey(session.session_id))
1145872
async def create(cls, fsm_context: FSMContext):
        
        proxy = cls(fsm_context)
        await proxy.load()
        return proxy
793962
def create_engine(
        database,
        minsize=1,
        maxsize=10,
        loop=None,
        dialect=_dialect,
        paramstyle=None,
        **kwargs):
    
    coro = _create_engine(
        database=database,
        minsize=minsize,
        maxsize=maxsize,
        loop=loop,
        dialect=dialect,
        paramstyle=paramstyle,
        **kwargs
    )
    return _EngineContextManager(coro)
907302
def initialize_connections(self, scopefunc=None):
        
        for connection_name, connection_string in\
                self.app.config['FLASK_PHILO_SQLALCHEMY'].items():
            engine = create_engine(connection_string)
            session = scoped_session(sessionmaker(), scopefunc=scopefunc)
            session.configure(bind=engine)
            self.connections[connection_name] = Connection(engine, session)
1300695
function extendContext(context, opts) {
  Object.defineProperties(context, {
    [CONTEXT_SESSION]: {
      get() {
        if (this[_CONTEXT_SESSION]) return this[_CONTEXT_SESSION];
        this[_CONTEXT_SESSION] = new ContextSession(this, opts);
        return this[_CONTEXT_SESSION];
      },
      enumerable: true
    },
    session: {
      get() {
        return this[CONTEXT_SESSION].get();
      },
      set(val) {
        this[CONTEXT_SESSION].set(val);
      },
      configurable: true,
      enumerable: true
    },
    sessionOptions: {
      get() {
        return this[CONTEXT_SESSION].opts;
      },
      enumerable: true
    },
  });
}
393313
def create_default_context(purpose=None, **kwargs):
    """"""
    if hasattr(ssl, 'create_default_context'):
        # Python 2.7.9+, Python 3.4+: take a server_side boolean or None, in
        # addition to the ssl.Purpose.XX values. This allows a user to write
        # code that works on all supported Python versions.
        if purpose is None or purpose is False:
            purpose = ssl.Purpose.SERVER_AUTH
        elif purpose is True:
            purpose = ssl.Purpose.CLIENT_AUTH
        return ssl.create_default_context(purpose, **kwargs)
    # Python 2.7.8, Python 3.3
    context = SSLContext(ssl.PROTOCOL_SSLv23)
    if kwargs.get('cafile'):
        context.load_verify_locations(kwargs['cafile'])
    return context