Get db session.

    :param url: URL for connect with DB
    :type url: :class:`str`

    :returns: A sqlalchemy db session
    :rtype: :class:`sqlalchemy.orm.Session`
355926
def get_session(url):
    
    engine = create_engine(url)
    db_session = scoped_session(sessionmaker(engine))
    Base.metadata.create_all(engine)
    return db_session
740350
def get(cls, group_id, db_session=None):
        
        db_session = get_db_session(db_session)
        return db_session.query(cls.model).get(group_id)
695880
def get(self, id):
        
        try:
            session_json = self.db[id]
        except KeyError:
            session_json = "{}"
        return json_loads(session_json)
1210244
async def fromURL(cls, url, *, credentials=None, insecure=False):
        """"""
        session = await bones.SessionAPI.fromURL(
            url, credentials=credentials, insecure=insecure)
        return cls(session)
1325384
def from_url(cls, url):
        
        parsed = urlparse(url)
        return cls(
            username=parsed.username,
            password=parsed.password,
            hostname=parsed.hostname,
            port=parsed.port,
            database=parsed.path.lstrip('/'),
            # Like parse_qs, but produces a scalar per key, instead of a list:
            query_params=dict(param.split('=')
                              for param in parsed.query.split('&'))
            if parsed.query else {},
        )
845374
def _request(self, url, params={}):
        
        r = self._session.get(url=url, params=params, headers=DEFAULT_ORIGIN)
        return r
1350948
def shell_sqlalchemy(session: SqlalchemySession, backend: ShellBackend):
    
    namespace = {
        'session': session
    }
    namespace.update(backend.get_namespace())
    embed(user_ns=namespace, header=backend.header)
575010
def _get_connection(self):
        
        if not getattr(self, '_connection', None):
            logger.debug(
                'Creating new connection.\n   dsn: {}'
                .format(self._dsn))

            d = parse_url_to_dict(self._dsn)
            self._connection = psycopg2.connect(
                database=d['path'].strip('/'), user=d['username'], password=d['password'],
                port=d['port'], host=d['hostname'])
            # It takes some time to find the way how to get raw connection from sqlalchemy. So,
            # I leave the commented code.
            #
            # self._engine = create_engine(self._dsn)
            # self._connection = self._engine.raw_connection()
            #
        return self._connection
1319846
def _get_request(self, url, headers, params=None):
        
        return self._session.get(url, headers=headers, params=params)
169790
def _db(self):
        
        if not hasattr(self, "_db_client") or getattr(self, "_db_client") is None:
            self._db_client = get_db_client()
        return self._db_client
625233
def get_db_session(engine):
    ""

    db = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
    db.configure(bind=engine)
    db.autoflush = True

    return db
310397
def open_session(self):
        
        from .dal import get_session

        cfg = Config()
        cfg.logger = self.logger
        db_path = cfg.get(ConfigKeys.asset_allocation_database_path)

        self.session = get_session(db_path)
        return self.session
1052639
def query(querystr, connection=None, **connectkwargs):
    
    if connection is None:
        connection = connect(**connectkwargs)
    cursor = connection.cursor()
    cursor.execute(querystr)
    return cursor.fetchall()
637165
def get_session_url(session_id, type='view', **params):
        
        url = 'sessions/{}/{}'.format(session_id, type)
        url = urljoin(API_URL, url)
        return add_to_url(url, **params)
813173
def _get_content(cls, url, headers=HTTP_HEADERS):
        
        session = requests.Session()
        return session.get(url, headers=headers)
825195
def _get(self, url, params=None):
        
        self._call(self.GET, url, params, None)
50608
def get_sessionmaker(sqlalchemy_url, engine=None):
    
    if engine is None:
        engine = create_engine(sqlalchemy_url)
    return sessionmaker(bind=engine)