Skip to content

Commit f820d71

Browse files
authored
feat: refactor parameter mapping (#32)
Enhance the way SQL Parameters are parsed and bound in statements.
1 parent 99d6de2 commit f820d71

40 files changed

+6536
-4208
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ default_language_version:
22
python: "3"
33
repos:
44
- repo: https://github.com/compilerla/conventional-pre-commit
5-
rev: v4.0.0
5+
rev: v4.2.0
66
hooks:
77
- id: conventional-pre-commit
88
stages: [commit-msg]
@@ -17,7 +17,7 @@ repos:
1717
- id: mixed-line-ending
1818
- id: trailing-whitespace
1919
- repo: https://github.com/charliermarsh/ruff-pre-commit
20-
rev: "v0.11.6"
20+
rev: "v0.11.9"
2121
hooks:
2222
- id: ruff
2323
args: ["--fix"]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ This list is not final. If you have a driver you'd like to see added, please ope
196196
| [`spanner`](https://googleapis.dev/python/spanner/latest/index.html) | Spanner | Sync | 🗓️ |
197197
| [`sqlserver`](https://docs.microsoft.com/en-us/sql/connect/python/pyodbc/python-sql-driver-for-pyodbc?view=sql-server-ver16) | SQL Server | Sync | 🗓️ |
198198
| [`mysql`](https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysql-connector-python.html) | MySQL | Sync | 🗓️ |
199+
| [`asyncmy`](https://github.com/long2ice/asyncmy) | MySQL | Async ||
199200
| [`snowflake`](https://docs.snowflake.com) | Snowflake | Sync | 🗓️ |
200201

201202
## Proposed Project Structure

docs/PYPI_README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ This list is not final. If you have a driver you'd like to see added, please ope
196196
| [`spanner`](https://googleapis.dev/python/spanner/latest/index.html) | Spanner | Sync | 🗓️ |
197197
| [`sqlserver`](https://docs.microsoft.com/en-us/sql/connect/python/pyodbc/python-sql-driver-for-pyodbc?view=sql-server-ver16) | SQL Server | Sync | 🗓️ |
198198
| [`mysql`](https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysql-connector-python.html) | MySQL | Sync | 🗓️ |
199+
| [`asyncmy`](https://github.com/long2ice/asyncmy) | MySQL | Async ||
199200
| [`snowflake`](https://docs.snowflake.com) | Snowflake | Sync | 🗓️ |
200201

201202
## Proposed Project Structure

docs/examples/litestar_asyncpg.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Litestar Asyncpg
2+
3+
This example demonstrates how to use a Asyncpg database in a Litestar application.
4+
5+
The example uses the `SQLSpec` extension to create a connection to a Asyncpg database.
6+
7+
The Asyncpg database also demonstrates how to use the plugin loader and `secrets` configuration manager built into SQLSpec.
8+
"""
9+
# /// script
10+
# dependencies = [
11+
# "sqlspec[psycopg,asyncpg,performance]",
12+
# "litestar[standard]",
13+
# ]
14+
# ///
15+
16+
from litestar import Litestar, get
17+
18+
from sqlspec.adapters.asyncpg import AsyncpgConfig, AsyncpgDriver, AsyncpgPoolConfig
19+
from sqlspec.extensions.litestar import DatabaseConfig, SQLSpec
20+
21+
22+
@get("/")
23+
async def simple_asyncpg(db_session: AsyncpgDriver) -> dict[str, str]:
24+
return await db_session.select_one("SELECT 'Hello, world!' AS greeting")
25+
26+
27+
sqlspec = SQLSpec(
28+
config=[
29+
DatabaseConfig(
30+
config=AsyncpgConfig(
31+
pool_config=AsyncpgPoolConfig(dsn="postgres://app:app@localhost:15432/app", min_size=1, max_size=3),
32+
),
33+
commit_mode="autocommit",
34+
)
35+
]
36+
)
37+
app = Litestar(route_handlers=[simple_asyncpg], plugins=[sqlspec])
38+
39+
if __name__ == "__main__":
40+
import os
41+
42+
from litestar.cli import litestar_group
43+
44+
os.environ["LITESTAR_APP"] = "docs.examples.litestar_asyncpg:app"
45+
46+
litestar_group()

docs/examples/litestar_psycopg.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""Litestar Psycopg
2+
3+
This example demonstrates how to use a Psycopg database in a Litestar application.
4+
5+
The example uses the `SQLSpec` extension to create a connection to a Psycopg database.
6+
7+
The Psycopg database also demonstrates how to use the plugin loader and `secrets` configuration manager built into SQLSpec.
8+
"""
9+
# /// script
10+
# dependencies = [
11+
# "sqlspec[psycopg]",
12+
# "litestar[standard]",
13+
# ]
14+
# ///
15+
16+
from litestar import Litestar, get
17+
18+
from sqlspec.adapters.psycopg import PsycopgAsyncConfig, PsycopgAsyncDriver, PsycopgAsyncPoolConfig
19+
from sqlspec.extensions.litestar import DatabaseConfig, SQLSpec
20+
21+
22+
@get("/")
23+
async def simple_psycopg(db_session: PsycopgAsyncDriver) -> dict[str, str]:
24+
return await db_session.select_one("SELECT 'Hello, world!' AS greeting")
25+
26+
27+
sqlspec = SQLSpec(
28+
config=[
29+
DatabaseConfig(
30+
config=PsycopgAsyncConfig(
31+
pool_config=PsycopgAsyncPoolConfig(
32+
conninfo="postgres://app:app@localhost:15432/app", min_size=1, max_size=3
33+
),
34+
),
35+
commit_mode="autocommit",
36+
)
37+
],
38+
)
39+
app = Litestar(route_handlers=[simple_psycopg], plugins=[sqlspec])
40+
41+
if __name__ == "__main__":
42+
import os
43+
44+
from litestar.cli import litestar_group
45+
46+
os.environ["LITESTAR_APP"] = "docs.examples.litestar_psycopg:app"
47+
48+
litestar_group()

pyproject.toml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ maintainers = [{ name = "Litestar Developers", email = "hello@litestar.dev" }]
77
name = "sqlspec"
88
readme = "README.md"
99
requires-python = ">=3.9, <4.0"
10-
version = "0.10.1"
10+
version = "0.11.0"
11+
12+
[project.urls]
13+
Discord = "https://discord.gg/litestar"
14+
Issue = "https://github.com/litestar-org/sqlspec/issues/"
15+
Source = "https://github.com/litestar-org/sqlspec"
1116

1217
[project.optional-dependencies]
1318
adbc = ["adbc_driver_manager", "pyarrow"]
@@ -249,6 +254,10 @@ module = [
249254
"pyarrow.*",
250255
]
251256

257+
[[tool.mypy.overrides]]
258+
disable_error_code = "ignore-without-code"
259+
module = "sqlspec.extensions.litestar.providers"
260+
252261
[tool.pyright]
253262
disableBytesTypePromotions = true
254263
exclude = ["**/node_modules", "**/__pycache__", ".venv", "tools", "docs"]
@@ -260,6 +269,8 @@ reportPrivateUsage = false
260269
reportUnknownArgumentType = false
261270
reportUnknownMemberType = false
262271
reportUnknownVariableType = false
272+
reportUnnecessaryComparison = false
273+
reportUnnecessaryIsInstance = false
263274
reportUnnecessaryTypeIgnoreComments = true
264275
root = "."
265276

@@ -318,7 +329,13 @@ select = ["ALL"]
318329
convention = "google"
319330

320331
[tool.ruff.lint.mccabe]
321-
max-complexity = 18
332+
max-complexity = 25
333+
334+
[tool.ruff.lint.pylint]
335+
max-bool-expr = 10
336+
max-branches = 20
337+
max-locals = 20
338+
max-returns = 15
322339

323340
[tool.ruff.lint.pep8-naming]
324341
classmethod-decorators = ["classmethod"]

sqlspec/adapters/adbc/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class AdbcConfig(NoPoolSyncConfig["AdbcConnection", "AdbcDriver"]):
3838
pool_instance: None = field(init=False, default=None, hash=False)
3939
"""No connection pool is used for ADBC connections"""
4040

41-
def _set_adbc(self) -> str: # noqa: PLR0912
41+
def _set_adbc(self) -> str:
4242
"""Identify the driver type based on the URI (if provided) or preset driver name.
4343
4444
Raises:

0 commit comments

Comments
 (0)