如何从SQLAlchemy Engine实例获取连接URL? [英] How can I get a connection URL from an SQLAlchemy Engine instance?
问题描述
我通过生成 URL
对象,并将其传递给 create_engine
。在一段很远的代码中,我想找出此引擎所连接的内容,即连接URL。
I begin a program by generating a URL
object and passing it to create_engine
. In a section of code far, far away I would like to find out what this engine is connected to, i.e. the connection URL.
有没有一种简便的方法可以做到这一点? ?使用 inspect
我只能看到如何获取驱动程序类型。我可以理解连接字符串的密码部分是否不再可用,但我希望其他所有内容仍然可用。
Is there an easy way to do this? Using inspect
I can only see how to get the driver type. I can understand if the password component of a connection string was no longer available, but I'm hoping everything else is still available.
有什么想法吗?
推荐答案
引擎类具有属性 url
。尽管未记录,但它不是下划线隐藏的,所以我会假设可以安全阅读。
The Engine class has an attribute url
. Although not documented, it is not 'underscore hidden' so I would assume safe to read.
这篇关于如何从SQLAlchemy Engine实例获取连接URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!