-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
944 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ name: Coverage | |
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
branches: [ "dev" ] | ||
|
||
jobs: | ||
build: | ||
|
@@ -11,12 +11,13 @@ jobs: | |
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
- run: pip install poetry | ||
- run: make install | ||
- run: | | ||
pip install poetry | ||
poetry install | ||
- name: Test & publish code coverage | ||
uses: paambaati/[email protected] | ||
env: | ||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} | ||
with: | ||
coverageCommand: make test-coverage | ||
coverageCommand: poetry run pytest --cov=simplecrud --cov-report xml | ||
debug: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: flake8 | ||
|
||
on: | ||
push: | ||
branches: [ "dev", "staging" ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
- run: | | ||
pip install poetry | ||
poetry install | ||
poetry run flake8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ __pycache__/ | |
*$py.class | ||
*cache* | ||
|
||
|
||
*test.db | ||
.idea/ | ||
.vscode/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,99 @@ | ||
# SimpleCRUD | ||
[![Maintainability](https://api.codeclimate.com/v1/badges/d33ecb2661fb7aedf516/maintainability)](https://codeclimate.com/github/hexfrost/sqlalchemy-models-commands/maintainability) | ||
[![Test Coverage](https://api.codeclimate.com/v1/badges/d33ecb2661fb7aedf516/test_coverage)](https://codeclimate.com/github/hexfrost/sqlalchemy-models-commands/test_coverage) | ||
[![flake8](https://github.com/hexfrost/simplecrud/actions/workflows/linter.yml/badge.svg?branch=staging)](https://github.com/hexfrost/simplecrud/actions/workflows/linter.yml) | ||
|
||
# SimpleCRUD | ||
SimpleCRUD is a library that provides a simple way to create CRUD commands for SQLAlchemy models. | ||
|
||
*** | ||
|
||
## Installation | ||
|
||
```bash | ||
pip install hexfrost-simplecrud | ||
``` | ||
``` | ||
poetry add hexfrost-simplecrud | ||
``` | ||
|
||
*** | ||
|
||
## Usage | ||
|
||
1. Create a model | ||
2. Create a CRUDConfig | ||
3. Set sessionmaker to CRUDConfig | ||
4. Import CRUD functions | ||
5. Use CRUD functions and enjoy | ||
|
||
### Example usage | ||
|
||
```python | ||
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker | ||
from sqlalchemy.orm import DeclarativeBase | ||
|
||
from simplecrud import CRUDConfig, BaseModelWithCRUD, get_all, create_obj, update_obj | ||
|
||
engine = create_async_engine("sqlite+aiosqlite:///test.db", echo=True) | ||
async_sessionmaker = async_sessionmaker(async_engine, expire_on_commit=False, class_=AsyncSession) | ||
|
||
# Create a model | ||
class ExampleModel(DeclarativeBase): | ||
__tablename__ = "example_model" | ||
id = Column(Integer, primary_key=True) | ||
name = Column(String(50), nullable=False) | ||
description = Column(String(50), nullable=False) | ||
|
||
|
||
# Create CRUD config | ||
CRUDConfig.sessionmaker(async_sessionmaker) | ||
|
||
async def example_func(): | ||
|
||
# Create a model | ||
new_model = await create_object(model, name="test", description="test") | ||
|
||
# Get all models | ||
all_objs = await get_all(model) | ||
|
||
# Update a model | ||
updated_obj = await update_object(model, name="test2", description="test2") | ||
|
||
# Delete a model | ||
await delete_object(model, name="test2", description="test2") | ||
|
||
``` | ||
|
||
### Avaliable functions: | ||
- `get_object` - get a single object | ||
- `get_all` - get all objects | ||
- `get_all_with_filter` - get all objects with filter | ||
- `get_objects` - get all objects with filter, limit and offset | ||
- `get_or_create_object` - get or create an object | ||
- `create_object` - create an object | ||
- `bulk_create` - create multiple objects | ||
- `update_object` - update an object | ||
- `update_or_error` - update an object or raise an error | ||
- `update_object_by_id` - update an object by id | ||
- `update_or_create_object` - update or create an object | ||
- `delete_object` - delete an object | ||
- `delete_object_by_id` - delete an object by id | ||
- `bulk_delete` - bulk delete objects | ||
- `bulk_delete_by_id` - bulk delete objects by id | ||
|
||
*** | ||
|
||
## Contributing | ||
|
||
This project is open for contributions. Feel free to open an issue or create a pull request. | ||
|
||
Dev version status: | ||
[![flake8](https://github.com/hexfrost/simplecrud/actions/workflows/linter.yml/badge.svg?branch=dev)](https://github.com/hexfrost/simplecrud/actions/workflows/linter.yml) | ||
[![Coverage](https://github.com/hexfrost/simplecrud/actions/workflows/coverage.yml/badge.svg?branch=dev)](https://github.com/hexfrost/simplecrud/actions/workflows/coverage.yml) | ||
|
||
*** | ||
|
||
## License | ||
|
||
```GNU GENERAL PUBLIC LICENSE Version 3``` | ||
|
Oops, something went wrong.