Skip to content
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

fix: type hint for 3.8 support #191

Merged
merged 4 commits into from
May 11, 2024
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
31 changes: 18 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ Check out the [project documentation][project-docs] 📚 for more information.
## About

A carefully crafted, thoroughly tested, optimized companion library for SQLAlchemy,
offering features such as:
offering:

- Sync and async repositories, featuring common CRUD and highly optimized bulk operations
- Integration with major web frameworks including Litestar, Starlette, FastAPI, Sanic.
- Integration with major web frameworks including Litestar, Starlette, FastAPI, Sanic
- Custom-built alembic configuration and CLI with optional framework integration
- Utility base classes with audit columns, primary keys and utility functions
- Optimized JSON types including a custom JSON type for Oracle.
- Optimized JSON types including a custom JSON type for Oracle
- Integrated support for UUID6 and UUID7 using [`uuid-utils`](https://github.com/aminalaee/uuid-utils) (install with the `uuid` extra)

- Pre-configured base classes with audit columns UUID or Big Integer primary keys and
a [sentinel column](https://docs.sqlalchemy.org/en/20/core/connections.html#configuring-sentinel-columns).
- Synchronous and asynchronous repositories featuring:
Expand All @@ -46,7 +45,6 @@ offering features such as:
for improved query building performance
- Integrated counts, pagination, sorting, filtering with `LIKE`, `IN`, and dates before and/or after.
- Tested support for multiple database backends including:

- SQLite via [aiosqlite](https://aiosqlite.omnilib.dev/en/stable/) or [sqlite](https://docs.python.org/3/library/sqlite3.html)
- Postgres via [asyncpg](https://magicstack.github.io/asyncpg/current/) or [psycopg3 (async or sync)](https://www.psycopg.org/psycopg3/)
- MySQL via [asyncmy](https://github.com/long2ice/asyncmy)
Expand All @@ -55,6 +53,7 @@ offering features such as:
- DuckDB via [duckdb_engine](https://github.com/Mause/duckdb_engine)
- Microsoft SQL Server via [pyodbc](https://github.com/mkleehammer/pyodbc) or [aioodbc](https://github.com/aio-libs/aioodbc)
- CockroachDB via [sqlalchemy-cockroachdb (async or sync)](https://github.com/cockroachdb/sqlalchemy-cockroachdb)
- ...and much more

## Usage

Expand Down Expand Up @@ -108,10 +107,10 @@ with session_factory() as db_session:
repo = UserRepository(session=db_session)
# 1) Create multiple users with `add_many`
bulk_users = [
{"email": 'cody@advanced-alchemy.dev', 'name': 'Cody'},
{"email": 'janek@advanced-alchemy.dev', 'name': 'Janek'},
{"email": 'peter@advanced-alchemy.dev', 'name': 'Peter'},
{"email": 'jacob@advanced-alchemy.dev', 'name': 'Jacob'}
{"email": 'cody@litestar.dev', 'name': 'Cody'},
{"email": 'janek@litestar.dev', 'name': 'Janek'},
{"email": 'peter@litestar.dev', 'name': 'Peter'},
{"email": 'jacob@litestar.dev', 'name': 'Jacob'}
]
objs = repo.add_many([User(**raw_user) for raw_user in bulk_users])
db_session.commit()
Expand All @@ -129,6 +128,7 @@ with session_factory() as db_session:
remaining_count = repo.count()
print(f"Found {remaining_count} remaining records after delete.")
```

</details>

For a full standalone example, see the sample [here][standalone-example]
Expand Down Expand Up @@ -181,10 +181,10 @@ with session_factory() as db_session:
service = UserService(session=db_session)
# 1) Create multiple users with `add_many`
objs = service.create_many([
{"email": 'cody@advanced-alchemy.dev', 'name': 'Cody'},
{"email": 'janek@advanced-alchemy.dev', 'name': 'Janek'},
{"email": 'peter@advanced-alchemy.dev', 'name': 'Peter'},
{"email": 'jacob@advanced-alchemy.dev', 'name': 'Jacob'}
{"email": 'cody@litestar.dev', 'name': 'Cody'},
{"email": 'janek@litestar.dev', 'name': 'Janek'},
{"email": 'peter@litestar.dev', 'name': 'Peter'},
{"email": 'jacob@litestar.dev', 'name': 'Jacob'}
])
print(objs)
print(f"Created {len(objs)} new objects.")
Expand All @@ -201,6 +201,7 @@ with session_factory() as db_session:
remaining_count = service.count()
print(f"Found {remaining_count} remaining records after delete.")
```

</details>

### Web Frameworks
Expand Down Expand Up @@ -230,6 +231,7 @@ alchemy = SQLAlchemyPlugin(
)
app = Litestar(plugins=[alchemy])
```

</details>

For a full Litestar example, check [here][litestar-example]
Expand All @@ -250,6 +252,7 @@ alchemy = StarletteAdvancedAlchemy(
config=SQLAlchemyAsyncConfig(connection_string="sqlite+aiosqlite:///test.sqlite"), app=app,
)
```

</details>

For a full FastAPI example, see [here][fastapi-example]
Expand All @@ -270,6 +273,7 @@ alchemy = StarletteAdvancedAlchemy(
config=SQLAlchemyAsyncConfig(connection_string="sqlite+aiosqlite:///test.sqlite"), app=app,
)
```

</details>

#### Sanic
Expand All @@ -290,6 +294,7 @@ alchemy = SanicAdvancedAlchemy(
)
Extend.register(alchemy)
```

</details>

## Contributing
Expand Down
4 changes: 2 additions & 2 deletions advanced_alchemy/service/pagination.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import Generic, TypeVar
from typing import Generic, List, TypeVar
from uuid import UUID

T = TypeVar("T")
Expand All @@ -16,7 +16,7 @@ class OffsetPagination(Generic[T]):

__slots__ = ("items", "limit", "offset", "total")

items: list[T]
items: List[T] # noqa: UP006
"""List of data being sent as part of the response."""
limit: int
"""Maximal number of items to send."""
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
html_theme_options = {
"logo_target": "/",
"github_repo_name": "advanced-alchemy",
"github_url": "https://github.com/litestar-org/advanced-alchemy",
"navigation_with_keys": True,
"nav_links": [ # TODO(provinzkraut): I need a guide on extra_navbar_items and its magic :P
{"title": "Home", "url": "index"},
Expand Down
Loading