Skip to content

Commit

Permalink
v1.2.0: fix typos, change repository methods, improve forward ref res…
Browse files Browse the repository at this point in the history
…olve, add tests (coverage 89%).
  • Loading branch information
ALittleMoron committed Apr 18, 2024
1 parent b92f881 commit d49a054
Show file tree
Hide file tree
Showing 13 changed files with 1,100 additions and 126 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,4 @@ jobs:
uses: ./.github/workflows/test.yaml
with:
coverage: true
python-version: ${{ matrix.python-version }}
quality:
name: "Code quality check (${{ matrix.python-version }}"
needs:
- test
strategy:
fail-fast: true
matrix:
python-version: ["3.12"]
poetry-version: ["1.8"]
uses: ./.github/workflows/lint.yaml
with:
python-version: ${{ matrix.python-version }}
22 changes: 21 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,24 @@ jobs:
run: make install
- name: Run the automated tests with coverage
if: ${{ inputs.coverage }}
run: make test
run: make test
- name: Coverage Badge
uses: tj-actions/coverage-badge-py@v2
- name: Verify Changed files
uses: tj-actions/verify-changed-files@v16
id: verify-changed-files
with:
files: coverage.svg
- name: Commit files
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add coverage.svg
git commit -m "Updated coverage.svg"
- name: Push changes
if: steps.verify-changed-files.outputs.files_changed == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.github_token }}
branch: ${{ github.ref }}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ format:
.PHONY: test
test:
@if [ -z $(PDM) ]; then echo "Poetry could not be found. See https://python-poetry.org/docs/"; exit 2; fi
$(PDM) run pytest ./tests --cov-report xml --cov-fail-under 60 --cov ./$(NAME) -v
$(PDM) run pytest ./tests --cov-report xml --cov-fail-under 60 --cov ./$(NAME) -vv


.PHONY: test_docker
Expand Down
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# sqlrepo

![coverage](./coverage.svg)

>SQLAlchemy repository pattern.
## Install
Expand Down Expand Up @@ -86,6 +88,23 @@ from other models.
Warning: if you specify column from other model, it may cause errors. For example, update
doesn't use it for filters, because joins are not presents in update.

Current implementation use these option in search_by and order_by params, if you pass them as
strings.

```python
from my_package.models import Admin

class AdminRepository(BaseSyncRepository[Admin]):
specific_column_mapping = {"custom_field": Admin.id, "other_field": Admin.name}


admins = AdminRepository(session).list(
search='abc',
search_by="other_field",
order_by='custom_field',
)
```

### `use_flush`

Uses as flag of `flush` method in SQLAlchemy session.
Expand Down Expand Up @@ -217,7 +236,7 @@ class YourUnitOfWork(BaseAsyncUnitOfWork):

# Your custom method, that works with your repositories and do business-logic.
async def work_with_repo_together(self, model_id: int):
your_model_instance = await self.your_model_repo.get({'id': model_id})
your_model_instance = await self.your_model_repo.get(filters={'id': model_id})
your_other_model_instance = await self.your_model_repo.list(
filters={'your_model_id': model_id},
)
Expand Down
16 changes: 8 additions & 8 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ lint.ignore = [
"PT016",
"ANN101",
"ANN102",
"PLR0913",
]

[tool.ruff.lint.pydocstyle]
Expand Down Expand Up @@ -158,15 +159,15 @@ dev = [

[project]
name = "sqlrepo"
version = "1.0.2"
version = "1.2.0"
description = "sqlalchemy repositories with crud operations and other utils for it."
authors = [{ name = "Dmitriy Lunev", email = "dima.lunev14@gmail.com" }]
requires-python = ">=3.11"
readme = "README.md"
license = { text = "MIT" }
dependencies = [
"sqlalchemy>=2.0.29",
"python-dev-utils[sqlalchemy_filters]>=1.2.3",
"python-dev-utils[sqlalchemy_filters]>=1.3.0",
]


Expand Down
Loading

0 comments on commit d49a054

Please sign in to comment.