示例#1
0
def admin_db_connection(db_url):
    url = copy_url(db_url)
    dbtype = url.get_dialect().name

    if dbtype == "postgresql":
        url.database = ""

        if not url.username:
            url.username = getpass.getuser()

    elif not dbtype == "sqlite":
        url.database = None

    if dbtype == "postgresql":
        with C(url, poolclass=NullPool, isolation_level="AUTOCOMMIT") as c:
            yield c

    elif dbtype == "mysql":
        with C(url, poolclass=NullPool) as c:
            c.execute("""
                SET sql_mode = 'ANSI';
            """)
            yield c

    elif dbtype == "sqlite":
        with C(url, poolclass=NullPool) as c:
            yield c
示例#2
0
文件: SAGreen.py 项目: facundo/pybald
def convert_url_to_connection_args(name_or_url, **kwargs):
    url = sqlalchemy.engine.url.make_url(name_or_url)
    dialect_cls = url.get_dialect()

    # get the correct DBAPI base on connection url
    dbapi_args = {}
    dbapi = dialect_cls.dbapi(**dbapi_args)

    # create the dialect
    dialect_args = {'dbapi':dbapi}
    dialect = dialect_cls(**dialect_args)

    # assemble connection arguments
    # for this dialect
    (cargs, connection_params) = dialect.create_connect_args(url)
    return dbapi, connection_params
示例#3
0
 def get_dialect_cls(url):
     url.drivername = "sqlite"
     return url.get_dialect()
示例#4
0
 def get_dialect_cls(url):
     url = url.set(drivername="sqlite")
     return url.get_dialect()
示例#5
0
 def get_dialect_cls(url):
     url.drivername = "sqlite"
     return url.get_dialect()