libsql / sqlalchemy-libsql

SQLAchemy dialect for libSQL
MIT License
20 stars 6 forks source link

Planning to add support to sqlalchemy 1.4? #5

Open SantiMNV opened 1 year ago

SantiMNV commented 1 year ago

Hi, I am developing a project in FastAPI and wishing to use turso. FastAPI works mainly with sqlmodel, a mix between pydantic and sqlalchemy. It does not support sqlalchemy 2.0 so far.

How to implement this project to use FastAPI? Is there a plan of migrating this to previous sqlalchemy versions?

Thanks!

barbieri commented 1 year ago

hi @SantiMNV we can look into porting it to older versions, will check about the priorities and when we could do it.

But if you're willing to do that, the code should be pretty simple: https://github.com/libsql/sqlalchemy-libsql/blob/main/sqlalchemy_libsql/__init__.py#L85

See we build on top of the sqlite3 dialect, since our Python API is compatible with dbapi2 (import sqlite3.dbapi2 can be replaced with import libsql_client.dbapi2), then we expose that in https://github.com/libsql/sqlalchemy-libsql/blob/main/sqlalchemy_libsql/__init__.py#L91, with connect() being rewritten to not restrict the URL to be only files https://github.com/libsql/sqlalchemy-libsql/blob/main/sqlalchemy_libsql/__init__.py#L109 (compare to https://github.com/sqlalchemy/sqlalchemy/blob/main/lib/sqlalchemy/dialects/sqlite/pysqlite.py#L578-L586)

Blastorios commented 11 months ago

Note: They have been making great progress in https://github.com/tiangolo/sqlmodel/pull/632 to make SQLModel work with SQLAlchemy 2.0.

Although backporting might still be an interesting use case (as I am sure there will be other packages relying on an older version of alchemy), this specific use case will most likely be solved in a short timeframe.

You can already use a temporary fork https://github.com/mbsantiago/sqlmodel if you are on a deadline (they have already been testing quite extensively).