SQLAlchemy: Get database name from engine

前端 未结 1 990
独厮守ぢ
独厮守ぢ 2020-12-21 00:09

After creating an SQLALchemy engine like this

engine = create_engine(\'mssql+pyodbc://user:pass@dbserver:port/db_name?driver=ODBC+Driver+13+for+         


        
相关标签:
1条回答
  • 2020-12-21 00:46

    The engine provides the connection information, so you can access those parameters. For example, if you're in the debugger, you can do:

    (pdb) pp dir(dbconn.engine.url)
    [...
     'database',
     'drivername',
     'get_backend_name',
     'get_dialect',
     'get_driver_name',
     'host',
     'password',
     'password_original',
     'port',
     'query',
     'translate_connect_args',
     'username']
    

    So the simple way to get at the database name is:

    engine.url.database
    
    0 讨论(0)
提交回复
热议问题