Skip to content

Commit

Permalink
Release 0.2.0 (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaziamov authored Jan 27, 2024
1 parent 64f34b2 commit 752a97e
Show file tree
Hide file tree
Showing 19 changed files with 944 additions and 186 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ name: Compatibility Check
on:
push:
branches:
- 'dev'
- 'staging'

jobs:
compatibility:
runs-on: ubuntu-20.04

strategy:
matrix:
python-version: [3.6, "3.10"]
python-version: [ 3.8, 3.9, "3.10", 3.11, 3.12 ]

steps:
- name: Checkout code
Expand All @@ -26,7 +26,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
poetry install --no-root
- name: Run compatibility tests
run: poetry run pytest
9 changes: 5 additions & 4 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Coverage

on:
push:
branches: [ "main" ]
branches: [ "dev" ]

jobs:
build:
Expand All @@ -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
17 changes: 17 additions & 0 deletions .github/workflows/linter.yml
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
2 changes: 1 addition & 1 deletion .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
- uses: actions/setup-python@v2
- run: pip install poetry
- run: poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
- run: poetry publish --build
- run: poetry publish --build
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ __pycache__/
*$py.class
*cache*


*test.db
.idea/
.vscode/

Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ build:
publish:
poetry publish --dry-run
package-install:
python3 -m pip install --user dist/*.whl --force
python3 -m pip install --user dist/*.whl --force
lint:
poetry run flake8 simplecrud
98 changes: 97 additions & 1 deletion README.md
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```

Loading

0 comments on commit 752a97e

Please sign in to comment.