Skip to content

feat: refactor parameter mapping #32

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

Merged
merged 11 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ default_language_version:
python: "3"
repos:
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v4.0.0
rev: v4.2.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
Expand All @@ -17,7 +17,7 @@ repos:
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.11.6"
rev: "v0.11.9"
hooks:
- id: ruff
args: ["--fix"]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ This list is not final. If you have a driver you'd like to see added, please ope
| [`spanner`](https://googleapis.dev/python/spanner/latest/index.html) | Spanner | Sync | 🗓️ |
| [`sqlserver`](https://docs.microsoft.com/en-us/sql/connect/python/pyodbc/python-sql-driver-for-pyodbc?view=sql-server-ver16) | SQL Server | Sync | 🗓️ |
| [`mysql`](https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysql-connector-python.html) | MySQL | Sync | 🗓️ |
| [`asyncmy`](https://github.com/long2ice/asyncmy) | MySQL | Async | ✅ |
| [`snowflake`](https://docs.snowflake.com) | Snowflake | Sync | 🗓️ |

## Proposed Project Structure
Expand Down
1 change: 1 addition & 0 deletions docs/PYPI_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ This list is not final. If you have a driver you'd like to see added, please ope
| [`spanner`](https://googleapis.dev/python/spanner/latest/index.html) | Spanner | Sync | 🗓️ |
| [`sqlserver`](https://docs.microsoft.com/en-us/sql/connect/python/pyodbc/python-sql-driver-for-pyodbc?view=sql-server-ver16) | SQL Server | Sync | 🗓️ |
| [`mysql`](https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysql-connector-python.html) | MySQL | Sync | 🗓️ |
| [`asyncmy`](https://github.com/long2ice/asyncmy) | MySQL | Async | ✅ |
| [`snowflake`](https://docs.snowflake.com) | Snowflake | Sync | 🗓️ |

## Proposed Project Structure
Expand Down
46 changes: 46 additions & 0 deletions docs/examples/litestar_asyncpg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Litestar Asyncpg

This example demonstrates how to use a Asyncpg database in a Litestar application.

The example uses the `SQLSpec` extension to create a connection to a Asyncpg database.

The Asyncpg database also demonstrates how to use the plugin loader and `secrets` configuration manager built into SQLSpec.
"""
# /// script
# dependencies = [
# "sqlspec[psycopg,asyncpg,performance]",
# "litestar[standard]",
# ]
# ///

from litestar import Litestar, get

from sqlspec.adapters.asyncpg import AsyncpgConfig, AsyncpgDriver, AsyncpgPoolConfig
from sqlspec.extensions.litestar import DatabaseConfig, SQLSpec


@get("/")
async def simple_asyncpg(db_session: AsyncpgDriver) -> dict[str, str]:
return await db_session.select_one("SELECT 'Hello, world!' AS greeting")


sqlspec = SQLSpec(
config=[
DatabaseConfig(
config=AsyncpgConfig(
pool_config=AsyncpgPoolConfig(dsn="postgres://app:app@localhost:15432/app", min_size=1, max_size=3),
),
commit_mode="autocommit",
)
]
)
app = Litestar(route_handlers=[simple_asyncpg], plugins=[sqlspec])

if __name__ == "__main__":
import os

from litestar.cli import litestar_group

os.environ["LITESTAR_APP"] = "docs.examples.litestar_asyncpg:app"

litestar_group()
48 changes: 48 additions & 0 deletions docs/examples/litestar_psycopg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Litestar Psycopg

This example demonstrates how to use a Psycopg database in a Litestar application.

The example uses the `SQLSpec` extension to create a connection to a Psycopg database.

The Psycopg database also demonstrates how to use the plugin loader and `secrets` configuration manager built into SQLSpec.
"""
# /// script
# dependencies = [
# "sqlspec[psycopg]",
# "litestar[standard]",
# ]
# ///

from litestar import Litestar, get

from sqlspec.adapters.psycopg import PsycopgAsyncConfig, PsycopgAsyncDriver, PsycopgAsyncPoolConfig
from sqlspec.extensions.litestar import DatabaseConfig, SQLSpec


@get("/")
async def simple_psycopg(db_session: PsycopgAsyncDriver) -> dict[str, str]:
return await db_session.select_one("SELECT 'Hello, world!' AS greeting")


sqlspec = SQLSpec(
config=[
DatabaseConfig(
config=PsycopgAsyncConfig(
pool_config=PsycopgAsyncPoolConfig(
conninfo="postgres://app:app@localhost:15432/app", min_size=1, max_size=3
),
),
commit_mode="autocommit",
)
],
)
app = Litestar(route_handlers=[simple_psycopg], plugins=[sqlspec])

if __name__ == "__main__":
import os

from litestar.cli import litestar_group

os.environ["LITESTAR_APP"] = "docs.examples.litestar_psycopg:app"

litestar_group()
21 changes: 19 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ maintainers = [{ name = "Litestar Developers", email = "hello@litestar.dev" }]
name = "sqlspec"
readme = "README.md"
requires-python = ">=3.9, <4.0"
version = "0.10.1"
version = "0.11.0"

[project.urls]
Discord = "https://discord.gg/litestar"
Issue = "https://github.com/litestar-org/sqlspec/issues/"
Source = "https://github.com/litestar-org/sqlspec"

[project.optional-dependencies]
adbc = ["adbc_driver_manager", "pyarrow"]
Expand Down Expand Up @@ -249,6 +254,10 @@ module = [
"pyarrow.*",
]

[[tool.mypy.overrides]]
disable_error_code = "ignore-without-code"
module = "sqlspec.extensions.litestar.providers"

[tool.pyright]
disableBytesTypePromotions = true
exclude = ["**/node_modules", "**/__pycache__", ".venv", "tools", "docs"]
Expand All @@ -260,6 +269,8 @@ reportPrivateUsage = false
reportUnknownArgumentType = false
reportUnknownMemberType = false
reportUnknownVariableType = false
reportUnnecessaryComparison = false
reportUnnecessaryIsInstance = false
reportUnnecessaryTypeIgnoreComments = true
root = "."

Expand Down Expand Up @@ -318,7 +329,13 @@ select = ["ALL"]
convention = "google"

[tool.ruff.lint.mccabe]
max-complexity = 18
max-complexity = 25

[tool.ruff.lint.pylint]
max-bool-expr = 10
max-branches = 20
max-locals = 20
max-returns = 15

[tool.ruff.lint.pep8-naming]
classmethod-decorators = ["classmethod"]
Expand Down
2 changes: 1 addition & 1 deletion sqlspec/adapters/adbc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AdbcConfig(NoPoolSyncConfig["AdbcConnection", "AdbcDriver"]):
pool_instance: None = field(init=False, default=None, hash=False)
"""No connection pool is used for ADBC connections"""

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

Raises:
Expand Down
Loading