Skip to content

Commit

Permalink
fix: type hint for 3.8 support (#191)
Browse files Browse the repository at this point in the history
* chore: fix type hint for 3.8 support

* docs: add github URL to docs

* chore: clean up readme verbiage

* chore: updated readme addresses
  • Loading branch information
cofin committed May 11, 2024
1 parent ee340d4 commit 2799a80
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
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

0 comments on commit 2799a80

Please sign in to comment.