sqlalchemy-dqlite 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of sqlalchemy-dqlite might be problematic. Click here for more details.

@@ -0,0 +1,76 @@
1
+ Metadata-Version: 2.4
2
+ Name: sqlalchemy-dqlite
3
+ Version: 0.1.0
4
+ Summary: SQLAlchemy 2.0 dialect for dqlite distributed SQLite
5
+ Project-URL: Homepage, https://github.com/antoineleclair/sqlalchemy-dqlite
6
+ Project-URL: Repository, https://github.com/antoineleclair/sqlalchemy-dqlite
7
+ Project-URL: Issues, https://github.com/antoineleclair/sqlalchemy-dqlite/issues
8
+ Author-email: Antoine Leclair <antoineleclair@gmail.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE.md
11
+ Keywords: database,distributed,dqlite,orm,sqlalchemy,sqlite
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Database
19
+ Classifier: Topic :: Database :: Database Engines/Servers
20
+ Classifier: Topic :: Database :: Front-Ends
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.13
23
+ Requires-Dist: dqlite-dbapi>=0.1.0
24
+ Requires-Dist: sqlalchemy>=2.0
25
+ Provides-Extra: dev
26
+ Requires-Dist: mypy>=1.0; extra == 'dev'
27
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
28
+ Requires-Dist: pytest-cov>=4.0; extra == 'dev'
29
+ Requires-Dist: pytest>=8.0; extra == 'dev'
30
+ Requires-Dist: ruff>=0.4; extra == 'dev'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # sqlalchemy-dqlite
34
+
35
+ SQLAlchemy 2.0 dialect for [dqlite](https://dqlite.io/).
36
+
37
+ ## Installation
38
+
39
+ ```bash
40
+ pip install sqlalchemy-dqlite
41
+ ```
42
+
43
+ ## Usage
44
+
45
+ ```python
46
+ from sqlalchemy import create_engine, text
47
+
48
+ # Sync
49
+ engine = create_engine("dqlite://localhost:9001/mydb")
50
+ with engine.connect() as conn:
51
+ result = conn.execute(text("SELECT 1"))
52
+ print(result.fetchone())
53
+
54
+ # Async
55
+ from sqlalchemy.ext.asyncio import create_async_engine
56
+
57
+ async_engine = create_async_engine("dqlite+aio://localhost:9001/mydb")
58
+ async with async_engine.connect() as conn:
59
+ result = await conn.execute(text("SELECT 1"))
60
+ print(result.fetchone())
61
+ ```
62
+
63
+ ## URL Format
64
+
65
+ ```
66
+ dqlite://host:port/database
67
+ dqlite+aio://host:port/database
68
+ ```
69
+
70
+ ## Development
71
+
72
+ See [DEVELOPMENT.md](DEVELOPMENT.md) for setup and contribution guidelines.
73
+
74
+ ## License
75
+
76
+ MIT
@@ -0,0 +1,10 @@
1
+ sqlalchemydqlite/__init__.py,sha256=U6HJs9l-kJxJ8cOTvguwccxTow_glWxInRkw47SLGL0,142
2
+ sqlalchemydqlite/aio.py,sha256=A1vVGpqndeaFE5i-GOt5K5M5Vl431ap2dRp4lMnM3p0,1446
3
+ sqlalchemydqlite/base.py,sha256=1dCYwqhn5e1gA4UwqlTZUsqFDHf_L99DyGNpIPbv8Lg,3769
4
+ sqlalchemydqlite/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ sqlalchemydqlite/requirements.py,sha256=1Yp5-WoHg--Lpg6NJtSgErnoRyEmfS5_s1EJrYpSdLw,1188
6
+ sqlalchemy_dqlite-0.1.0.dist-info/METADATA,sha256=2EMJM3dXgNruBpnCr2XJe0NbQlJ2scE7urj3lOYwtf0,2166
7
+ sqlalchemy_dqlite-0.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
8
+ sqlalchemy_dqlite-0.1.0.dist-info/entry_points.txt,sha256=y_yQjMEFbOdy-Hh7af9IOlIUOiOcHYSEFDOtDqlgJbE,114
9
+ sqlalchemy_dqlite-0.1.0.dist-info/licenses/LICENSE.md,sha256=25ur0qy0m17OgHzc1Ve3NeLumyjGGgVBrN-JL3znfDg,1090
10
+ sqlalchemy_dqlite-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.28.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [sqlalchemy.dialects]
2
+ dqlite = sqlalchemydqlite:DqliteDialect
3
+ dqlite.aio = sqlalchemydqlite.aio:DqliteDialect_aio
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Antoine Leclair and Greg Sadetsky
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,7 @@
1
+ """SQLAlchemy 2.0 dialect for dqlite."""
2
+
3
+ from sqlalchemydqlite.base import DqliteDialect
4
+
5
+ __all__ = ["DqliteDialect"]
6
+
7
+ __version__ = "0.1.0"
@@ -0,0 +1,57 @@
1
+ """Async dqlite dialect for SQLAlchemy."""
2
+
3
+ from typing import Any
4
+
5
+ from sqlalchemy import pool
6
+ from sqlalchemy.dialects.sqlite.base import SQLiteDialect
7
+ from sqlalchemy.engine import URL
8
+ from sqlalchemy.pool import AsyncAdaptedQueuePool
9
+
10
+
11
+ class DqliteDialect_aio(SQLiteDialect): # noqa: N801
12
+ """Async SQLAlchemy dialect for dqlite.
13
+
14
+ Use with SQLAlchemy's async engine:
15
+ create_async_engine("dqlite+aio://host:port/database")
16
+ """
17
+
18
+ name = "dqlite"
19
+ driver = "dqlitedbapi_aio"
20
+ is_async = True
21
+
22
+ # dqlite uses qmark parameter style
23
+ paramstyle = "qmark"
24
+
25
+ @classmethod
26
+ def get_pool_class(cls, url: URL) -> type[pool.Pool]:
27
+ return AsyncAdaptedQueuePool
28
+
29
+ @classmethod
30
+ def import_dbapi(cls) -> Any:
31
+ from dqlitedbapi import aio
32
+
33
+ return aio
34
+
35
+ def create_connect_args(self, url: URL) -> tuple[list[Any], dict[str, Any]]:
36
+ """Create connection arguments from URL.
37
+
38
+ URL format: dqlite+aio://host:port/database
39
+ """
40
+ host = url.host or "localhost"
41
+ port = url.port or 9001
42
+ database = url.database or "default"
43
+
44
+ address = f"{host}:{port}"
45
+
46
+ return [], {
47
+ "address": address,
48
+ "database": database,
49
+ }
50
+
51
+ def get_driver_connection(self, connection: Any) -> Any:
52
+ """Return the driver-level connection."""
53
+ return connection
54
+
55
+
56
+ # Register the dialect
57
+ dialect = DqliteDialect_aio
@@ -0,0 +1,122 @@
1
+ """Base dqlite dialect for SQLAlchemy."""
2
+
3
+ from typing import Any
4
+
5
+ from sqlalchemy import pool
6
+ from sqlalchemy.dialects.sqlite.base import SQLiteDialect
7
+ from sqlalchemy.engine import URL
8
+ from sqlalchemy.engine.interfaces import DBAPIConnection, IsolationLevel
9
+
10
+
11
+ class DqliteDialect(SQLiteDialect):
12
+ """SQLAlchemy dialect for dqlite.
13
+
14
+ Inherits from SQLite dialect since dqlite is compatible with SQLite.
15
+ """
16
+
17
+ name = "dqlite"
18
+ driver = "dqlitedbapi"
19
+
20
+ # dqlite uses qmark parameter style
21
+ paramstyle = "qmark"
22
+
23
+ # Enable SQLAlchemy statement caching
24
+ supports_statement_cache = True
25
+
26
+ # Default to NullPool since dqlite handles connection pooling internally
27
+ @classmethod
28
+ def get_pool_class(cls, url: URL) -> type[pool.Pool]:
29
+ return pool.NullPool
30
+
31
+ @classmethod
32
+ def import_dbapi(cls) -> Any:
33
+ import dqlitedbapi
34
+
35
+ return dqlitedbapi
36
+
37
+ def create_connect_args(self, url: URL) -> tuple[list[Any], dict[str, Any]]:
38
+ """Create connection arguments from URL.
39
+
40
+ URL format: dqlite://host:port/database
41
+ """
42
+ host = url.host or "localhost"
43
+ port = url.port or 9001
44
+ database = url.database or "default"
45
+
46
+ address = f"{host}:{port}"
47
+
48
+ return [], {
49
+ "address": address,
50
+ "database": database,
51
+ }
52
+
53
+ def get_isolation_level(self, dbapi_connection: DBAPIConnection) -> IsolationLevel:
54
+ """Return the isolation level.
55
+
56
+ dqlite doesn't support PRAGMA read_uncommitted, so we return
57
+ SERIALIZABLE as the default isolation level.
58
+ """
59
+ return "SERIALIZABLE"
60
+
61
+ def set_isolation_level(self, dbapi_connection: DBAPIConnection, level: str | None) -> None:
62
+ """Set isolation level.
63
+
64
+ dqlite doesn't support changing isolation levels via PRAGMA,
65
+ so this is a no-op. dqlite uses SERIALIZABLE isolation by default.
66
+ """
67
+ pass
68
+
69
+ def do_rollback(self, dbapi_connection: DBAPIConnection) -> None:
70
+ """Rollback the current transaction.
71
+
72
+ dqlite throws an error if we try to rollback when no transaction
73
+ is active, so we catch and ignore that specific error.
74
+ """
75
+ try:
76
+ dbapi_connection.rollback()
77
+ except Exception as e:
78
+ # Ignore "no transaction is active" errors
79
+ if "no transaction is active" not in str(e):
80
+ raise
81
+
82
+ def do_commit(self, dbapi_connection: DBAPIConnection) -> None:
83
+ """Commit the current transaction.
84
+
85
+ dqlite throws an error if we try to commit when no transaction
86
+ is active, so we catch and ignore that specific error.
87
+ """
88
+ try:
89
+ dbapi_connection.commit()
90
+ except Exception as e:
91
+ # Ignore "no transaction is active" errors
92
+ if "no transaction is active" not in str(e):
93
+ raise
94
+
95
+ def do_ping(self, dbapi_connection: Any) -> bool:
96
+ """Check if the connection is still alive."""
97
+ try:
98
+ cursor = dbapi_connection.cursor()
99
+ cursor.execute("SELECT 1")
100
+ cursor.close()
101
+ return True
102
+ except Exception:
103
+ return False
104
+
105
+ def _get_server_version_info(self, connection: Any) -> tuple[int, ...]:
106
+ """Return the server version as a tuple.
107
+
108
+ dqlite uses SQLite internally, so we return SQLite version.
109
+ """
110
+ cursor = connection.connection.dbapi_connection.cursor()
111
+ cursor.execute("SELECT sqlite_version()")
112
+ row = cursor.fetchone()
113
+ cursor.close()
114
+
115
+ if row:
116
+ version_str = row[0]
117
+ return tuple(int(x) for x in version_str.split("."))
118
+ return (3, 0, 0)
119
+
120
+
121
+ # Register the dialect
122
+ dialect = DqliteDialect
File without changes
@@ -0,0 +1,45 @@
1
+ """SQLAlchemy test suite requirements for dqlite dialect."""
2
+
3
+ from sqlalchemy.testing.requirements import SuiteRequirements
4
+
5
+
6
+ class Requirements(SuiteRequirements):
7
+ """Test suite requirements for dqlite dialect.
8
+
9
+ Override requirements that dqlite doesn't support.
10
+ """
11
+
12
+ @property
13
+ def datetime_literals(self) -> bool:
14
+ """dqlite/SQLite doesn't have native datetime literals."""
15
+ return False
16
+
17
+ @property
18
+ def time_microseconds(self) -> bool:
19
+ """SQLite stores time as text without microseconds."""
20
+ return False
21
+
22
+ @property
23
+ def datetime_historic(self) -> bool:
24
+ """SQLite date range limitation."""
25
+ return False
26
+
27
+ @property
28
+ def unicode_ddl(self) -> bool:
29
+ """SQLite supports unicode in DDL."""
30
+ return True
31
+
32
+ @property
33
+ def savepoints(self) -> bool:
34
+ """dqlite supports savepoints."""
35
+ return True
36
+
37
+ @property
38
+ def two_phase_transactions(self) -> bool:
39
+ """dqlite doesn't support two-phase transactions."""
40
+ return False
41
+
42
+ @property
43
+ def temp_table_reflection(self) -> bool:
44
+ """SQLite supports temp table reflection."""
45
+ return True