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

Update README #23

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Changes from all commits
Commits
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
23 changes: 8 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[![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.

Expand All @@ -21,8 +22,7 @@ poetry add hexfrost-simplecrud
## Usage

1. Create a model
2. Create a CRUDConfig
3. Set sessionmaker to CRUDConfig
2. Create a sessionmaker from SQLAlchemy
4. Import CRUD functions
5. Use CRUD functions and enjoy

Expand All @@ -32,10 +32,10 @@ poetry add hexfrost-simplecrud
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
from simplecrud import get_all, create_obj, update_obj, delete_object

engine = create_async_engine("sqlite+aiosqlite:///test.db", echo=True)
async_sessionmaker = async_sessionmaker(async_engine, expire_on_commit=False, class_=AsyncSession)
session = async_sessionmaker(async_engine, expire_on_commit=False, class_=AsyncSession)

# Create a model
class ExampleModel(DeclarativeBase):
Expand All @@ -45,22 +45,19 @@ class ExampleModel(DeclarativeBase):
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")
new_model = await create_object(model, name="test", description="test", conn=session())

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

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

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

```

Expand All @@ -87,10 +84,6 @@ async def example_func():

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
Expand Down