New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Separate DB Drivers Required? #240
Comments
Installing psycopg2, pip install psycopg2-binary, and designating it as the dialect in the Sqlalchemy connection string allows successful creation of the database while Databases still uses asyncpg driver. I assume Databases does not let you specify a dialect in the connection string because currently only asyncpg is supported.
It would be nice to either reduce the complexity by eventually moving to a cross-compatible driver, or more clearly define this nuance in examples and documentation. (Unless I missed it somewhere.) Thanks again for your work on this, it looks promising! |
I know there is limited benefit because you only do this once at the start, but I threw a quick convenience class together, just to practice with Dataclasses:
Usage
|
Came across something similar today, when I tried (and failed) to do |
We no longer require synchronous drivers, as we should. sqla/alembic are synchronous. |
@vmarkovtsev Thanks for the comment. |
The README has this info now. |
If the need is to create and interact with a Postgres database, it seems from the documentation that standard SQL queries are executed to create the tables. Once created Databases can interact with them using the Sqlalchemy (SQLA) Core syntax.
What if we wish to generate the database using SQLA syntax as well with create_all() and not standard SQL?
The following code fails with app.models.sqla holding valid SQLA models to create the database:
Error:
ModuleNotFoundError: No module named 'psycopg2'
Attempts to define the driver dialect explicitly fail as well with "postgresql+asnycpg://..."
Databases does not support psycopg2 and SQLA does not support asyncpg. This presents some complexity right off the bat. Is it standard practice to import both drivers; psycopg2 to create the database, and then use the database through Databases with asyncpg?
The text was updated successfully, but these errors were encountered: