Skip to content

Commit

Permalink
feat: alembic and various framework integrations (#2)
Browse files Browse the repository at this point in the history
Co-authored-by: Janek Nouvertné <provinzkraut@posteo.de>
Co-authored-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
  • Loading branch information
3 people committed Sep 14, 2023
1 parent 4a74c71 commit a03cec8
Show file tree
Hide file tree
Showing 64 changed files with 5,421 additions and 238 deletions.
20 changes: 17 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,49 @@ repos:
- id: unasyncd
additional_dependencies: ["ruff"]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.287"
rev: "v0.0.289"
hooks:
- id: ruff
args: ["--fix"]
exclude: "docs"
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
hooks:
- id: codespell
exclude: "tests/openapi/typescript_converter/test_converter"
exclude: "pdm.lock"
- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.9.1
hooks:
- id: black
args: [--config=./pyproject.toml]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.5.1"
hooks:
- id: mypy
exclude: "docs"
additional_dependencies:
[
aiosqlite,
alembic,
async_timeout,
asyncmy,
asyncpg,
asyncpg_stubs,
oracledb,
psycopg,
pytest,
pytest-asyncio,
pytest-lazy-fixture,
time-machine,
httpx,
"sanic[ext]",
socketify,
fastapi,
pytest-mock,
pytest-timeout,
sqlalchemy>=2.0.12,
msgspec,
click,
rich,
"litestar[cli]",
]
105 changes: 69 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ help: ## Display this help text for Makefile

.PHONY: upgrade
upgrade: ## Upgrade all dependencies to the latest stable versions
@echo "=> Updating all dependencies"
@if [ "$(USING_PDM)" ]; then $(PDM) update; fi
@echo "=> Dependencies Updated"
$(ENV_PREFIX)pre-commit autoupdate
@$(ENV_PREFIX)pre-commit autoupdate
@echo "=> Updated Pre-commit"

# =============================================================================
Expand All @@ -37,55 +38,81 @@ install: ## Install the project and
@if [ "$(VENV_EXISTS)" ]; then echo "=> Removing existing virtual environment"; fi
if [ "$(VENV_EXISTS)" ]; then $(MAKE) destroy; fi
if [ "$(VENV_EXISTS)" ]; then $(MAKE) clean; fi
if [ "$(USING_PDM)" ]; then $(PDM) config venv.in_project true && python3 -m venv --copies .venv && . $(ENV_PREFIX)/activate && $(ENV_PREFIX)/pip install -U wheel setuptools cython pip; fi
if [ "$(USING_PDM)" ]; then $(PDM) install -G:all; fi
@if [ "$(USING_PDM)" ]; then $(PDM) config venv.in_project true && python3 -m venv --copies .venv && . $(ENV_PREFIX)/activate && $(ENV_PREFIX)/pip install --quiet -U wheel setuptools cython pip; fi
@if [ "$(USING_PDM)" ]; then $(PDM) install -G:all; fi
@echo "=> Install complete! Note: If you want to re-install re-run 'make install'"


clean: ## Cleanup temporary build artifacts
rm -rf .pytest_cache
rm -rf .ruff_cache
rm -rf .hypothesis
rm -rf build/
rm -rf dist/
rm -rf .eggs/
find . -name '*.egg-info' -exec rm -rf {} +
find . -name '*.egg' -exec rm -f {} +
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -rf {} +
find . -name '.ipynb_checkpoints' -exec rm -rf {} +
rm -rf .coverage
rm -rf coverage.xml
rm -rf coverage.json
rm -rf htmlcov/
rm -rf .pytest_cache
rm -rf tests/.pytest_cache
rm -rf tests/**/.pytest_cache
rm -rf .mypy_cache
find tools/downloads -type f -delete
@echo "=> Cleaning working directory"
@rm -rf .pytest_cache .ruff_cache .hypothesis build/ -rf dist/ .eggs/
@find . -name '*.egg-info' -exec rm -rf {} +
@find . -name '*.egg' -exec rm -f {} +
@find . -name '*.pyc' -exec rm -f {} +
@find . -name '*.pyo' -exec rm -f {} +
@find . -name '*~' -exec rm -f {} +
@find . -name '__pycache__' -exec rm -rf {} +
@find . -name '.ipynb_checkpoints' -exec rm -rf {} +
@rm -rf .coverage coverage.xml coverage.json htmlcov/ .pytest_cache tests/.pytest_cache tests/**/.pytest_cache .mypy_cache
$(MAKE) docs-clean

destroy: ## Destroy the virtual environment
rm -rf .venv
@rm -rf .venv

# =============================================================================
# Tests, Linting, Coverage
# =============================================================================
.PHONY: lint
lint: ## Runs pre-commit hooks; includes ruff linting, codespell, black
$(ENV_PREFIX)pre-commit run --all-files
@echo "=> Running pre-commit process"
@$(ENV_PREFIX)pre-commit run --all-files
@echo "=> Pre-commit complete"

.PHONY: coverage
coverage: ## Run the tests and generate coverage report
@echo "=> Running tests with coverage"
@$(ENV_PREFIX)pytest tests --cov=app
@$(ENV_PREFIX)coverage html
@$(ENV_PREFIX)coverage xml
@echo "=> Coverage report generated"

.PHONY: test
test: ## Run the tests
$(ENV_PREFIX)pytest tests
@echo "=> Running test cases"
@$(ENV_PREFIX)pytest tests
@echo "=> Tests complete"

.PHONY: coverage
coverage: ## Run the tests and generate coverage report
$(ENV_PREFIX)pytest tests --cov=app
$(ENV_PREFIX)coverage html
$(ENV_PREFIX)coverage xml
.PHONY: test-asyncpg
test-asyncpg:
$(ENV_PREFIX)pytest tests -m='integration and asyncpg'

.PHONY: test-psycopg-async
test-psycopg-async:
$(ENV_PREFIX)pytest tests -m='integration and psycopg_async'

.PHONY: test-psycopg-sync
test-psycopg-sync:
$(ENV_PREFIX)pytest tests -m='integration and psycopg_sync'

.PHONY: test-asyncmy
test-asyncmy:
$(ENV_PREFIX)pytest tests -m='integration and asyncmy'

.PHONY: test-oracledb
test-oracledb:
$(ENV_PREFIX)pytest tests -m='integration and oracledb'

.PHONY: test-duckdb
test-duckdb:
$(ENV_PREFIX)pytest tests -m='integration and duckdb'

.PHONY: test-spanner
test-spanner:
$(ENV_PREFIX)pytest tests -m='integration and spanner'

.PHONY: test-all-databases
test-all-databases:
$(ENV_PREFIX)pytest tests -m='integration and integration'

.PHONY: check-all
check-all: lint test coverage ## Run all linting, tests, and coverage checks
Expand All @@ -95,13 +122,19 @@ check-all: lint test coverage ## Run all linting, tests, and coverage chec
# =============================================================================
.PHONY: docs-install
docs-install: ## Install docs dependencies
$(PDM) install --group docs
@echo "=> Installing documentation dependencies"
@$(PDM) install --group docs
@echo "=> Installed documentation dependencies"

docs-clean: ## Dump the existing built docs
rm -rf docs/_build
@echo "=> Cleaning documentation build assets"
@rm -rf docs/_build
@echo "=> Removed existing documentation build assets"

docs-serve: docs-clean ## Serve the docs locally
@echo "=> Serving documentation"
$(ENV_PREFIX)sphinx-autobuild docs docs/_build/ -j auto --watch app --watch docs --watch tests --watch CONTRIBUTING.rst --port 8002

docs: docs-clean ## Dump the existing built docs and rebuild them
$(ENV_PREFIX)sphinx-build -M html docs docs/_build/ -E -a -j auto --keep-going
@echo "=> Building documentation"
@$(ENV_PREFIX)sphinx-build -M html docs docs/_build/ -E -a -j auto --keep-going
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ A carefully crafted, thoroughly tested, optimized companion library for SQLAlche
offering features such as:

- Sync and async repositories, featuring common CRUD and highly optimized bulk operations
- Integration with major web frameworks (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
- Optimized JSON types including a custom JSON type for Oracle.

* 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:
* Common CRUD operations for SQLAlchemy models
* Bulk inserts, updates, upserts, and deletes with dialect-specific enhancements
* [lambda_stmt](https://docs.sqlalchemy.org/en/20/core/sqlelement.html#sqlalchemy.sql.expression.lambda_stmt) when possible
- 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:
- Common CRUD operations for SQLAlchemy models
- Bulk inserts, updates, upserts, and deletes with dialect-specific enhancements
- [lambda_stmt](https://docs.sqlalchemy.org/en/20/core/sqlelement.html#sqlalchemy.sql.expression.lambda_stmt) when possible
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:
- 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/)
- 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)
- Oracle via [oracledb](https://oracle.github.io/python-oracledb/)
- Google Spanner via [spanner-sqlalchemy](https://github.com/googleapis/python-spanner-sqlalchemy/)
Expand Down
Empty file.

0 comments on commit a03cec8

Please sign in to comment.