Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.3.0 #24

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
272d13d
Ref/add tests (#8)
kaziamov Jan 20, 2024
bf0d67e
Tests/add crud tests (#9)
kaziamov Jan 21, 2024
3f85104
Feat/update 2 (#10)
kaziamov Jan 21, 2024
f5f2a84
Update README.md (#11)
kaziamov Jan 21, 2024
231ea8d
Merge branch 'main' into dev
kaziamov Jan 21, 2024
3191b0b
Feat/update 3 (#14)
kaziamov Jan 27, 2024
4f07808
Update coverage.yml
kaziamov Jan 27, 2024
7bf2492
Merge pull request #15 from hexfrost/kaziamov-patch-3
kaziamov Jan 27, 2024
ff7237c
Remove test.db from repo
kaziamov Jan 27, 2024
9347445
Remove inside logging
kaziamov Jan 27, 2024
2dfca6c
Add linter command
kaziamov Jan 27, 2024
9789ebb
Add flake8 config
kaziamov Jan 27, 2024
3d2ac4a
Update
kaziamov Jan 27, 2024
3ff657d
Update
kaziamov Jan 27, 2024
2586682
Merge pull request #16 from hexfrost/feat/update-4
kaziamov Jan 27, 2024
cebf4d2
Update setup.cfg
kaziamov Jan 27, 2024
f973e27
Update coverage.yml
kaziamov Jan 27, 2024
099895f
Fix test
kaziamov Jan 27, 2024
69c16aa
Add coverage lib
kaziamov Jan 27, 2024
cd4892e
Update import
kaziamov Jan 27, 2024
3f1cbd3
Remove useless tests
kaziamov Jan 27, 2024
874ee23
Update tests
kaziamov Jan 27, 2024
769a1ff
Add typing
kaziamov Jan 27, 2024
3bb47c2
Update tests
kaziamov Jan 27, 2024
0c106b2
Merge pull request #17 from hexfrost/feat/update-5
kaziamov Jan 27, 2024
4e59b80
Update __init__.py
kaziamov Jan 27, 2024
c865526
Comment useless test
kaziamov Jan 27, 2024
2cd5800
Update README.md
kaziamov Jan 27, 2024
9f4464d
Update linter yml
kaziamov Jan 27, 2024
08a5c24
Update configs and README
kaziamov Jan 27, 2024
cfdde48
Update README
kaziamov Jan 27, 2024
8b3e93b
Update project version
kaziamov Jan 27, 2024
e3078d5
Update python version
kaziamov Jan 27, 2024
9ebfa7d
Remove problematic code
kaziamov Mar 2, 2024
d3c9a84
Merge pull request #20 from hexfrost/feat/update-6
kaziamov Mar 2, 2024
df22d25
Fix bug and tests
kaziamov Mar 3, 2024
06fe87f
Merge pull request #21 from hexfrost/feat/update-6
kaziamov Mar 3, 2024
e7577ea
Update max-length settings and reformat code
kaziamov Mar 3, 2024
e2d8ba3
Merge pull request #22 from hexfrost/feat/fix-linter
kaziamov Mar 3, 2024
a9025ef
Update README
kaziamov Mar 3, 2024
b1e0cd0
Merge pull request #23 from hexfrost/docs/update-readme
kaziamov Mar 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
91 changes: 90 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,92 @@
# 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 sessionmaker from SQLAlchemy
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 get_all, create_obj, update_obj, delete_object

engine = create_async_engine("sqlite+aiosqlite:///test.db", echo=True)
session = 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)


async def example_func():

# Create a model
new_model = await create_object(model, name="test", description="test", conn=session())

# Get all models
all_objs = await get_all(model, conn=session())

# Update a model
updated_obj = await update_object(model, name="test2", description="test2", conn=session())

# Delete a model
await delete_object(model, name="test2", description="test2", conn=session())

```

### 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.

***

## License

```GNU GENERAL PUBLIC LICENSE Version 3```

Loading
Loading