Doug
Doug

Reputation: 35166

How do you determine sqlalchemy driver from the session?

Some libraries and sites (like kotti) expose a database session that is loaded from a configuration file (it uses pyramid).

In general you can ignore the driver for sqlalchemy, but there are a few issues like getting a random row and using timezones with sqlite, which require you to have specific behavior for different engines.

Thing is, I can't see to find out how to determine what driver you're using at run time.

How do you do this?

Specifically, how, from a session (not an engine or a session factory) can you work backwards and figure this out?

Upvotes: 13

Views: 6327

Answers (1)

javex
javex

Reputation: 7544

If you do this

session.bind.dialect.name

it will return something like sqlite or mysql, i.e. the part at the beginning of a URL (mysql://...). Most other information can also be fetched from the dialect object if you are interested in more. You can find this on any engine or connection (which bind is).

Upvotes: 24

Related Questions