|
| 1 | +r""" |
| 2 | +.. dialect:: sqlite+libsql_async |
| 3 | + :name: libsql_async |
| 4 | + :dbapi: libsql_client.dbapi2 |
| 5 | + :connectstring: sqlite+libsql_async://your-db.your-server.com?authToken=JWT_HERE&secure=true |
| 6 | + :url: https://github.com/libsql/libsql-client-py/ |
| 7 | +
|
| 8 | + Note that this driver is based on the standard SQLAlchemy ``pysqlite`` |
| 9 | + dialect, the only change is how to connect, accepting remote URL in |
| 10 | + addition to the file dialects |
| 11 | +
|
| 12 | + Disclaimer: While this dialect allows for async_engine compatibility with |
| 13 | + libsql, the dbapi remains synchronous |
| 14 | +
|
| 15 | +Driver |
| 16 | +------ |
| 17 | +
|
| 18 | +The ``libsql_client.dbapi2`` offers compatibility with standard library's |
| 19 | +``sqlite3.dbapi2``. For local files or ``:memory:``, the standard library |
| 20 | +connection is used. Whenever a host is provided, then the connection |
| 21 | +will use LibSQL network protocol via ``ws`` (WebSocket) or ``wss`` |
| 22 | +(secure WebSocket), the decision depends on the presence of ``secure=true`` |
| 23 | +query parameter. |
| 24 | +
|
| 25 | +Connect Strings |
| 26 | +--------------- |
| 27 | +
|
| 28 | +In addition to `Pysqlite |
| 29 | +<https://docs.sqlalchemy.org/en/20/dialects/sqlite.html#connect-strings>`_, |
| 30 | +this driver accepts URL with user, password, hostname and port. |
| 31 | +
|
| 32 | +These will use the LibSQL network protocol on top of WebSockets. The selection |
| 33 | +between ``ws://`` and ``wss://` (secure) is defined by the query/search |
| 34 | +parameter ``secure=true``. It defaults to ``secure=false``. |
| 35 | +
|
| 36 | +If the given URL provides a hostname, then it will default to ``uri=true``. |
| 37 | +
|
| 38 | +""" # noqa: E501 |
| 39 | + |
| 40 | +from sqlalchemy_libsql.libsql import SQLiteDialect_libsql |
| 41 | + |
| 42 | + |
| 43 | +class SQLiteDialect_libsql_async(SQLiteDialect_libsql): |
| 44 | + driver = "libsql" |
| 45 | + # need to be set explicitly |
| 46 | + supports_statement_cache = SQLiteDialect_libsql.supports_statement_cache |
| 47 | + is_async = True |
| 48 | + |
| 49 | + |
| 50 | +dialect = SQLiteDialect_libsql_async |
0 commit comments