Library with operation like (get, create, update, delete) for SQLAlchemy ORM
Project description
SimpleCRUD
SimpleCRUD is a library that provides a simple way to create CRUD commands for SQLAlchemy models.
Installation
pip install hexfrost-simplecrud
poetry add hexfrost-simplecrud
Usage
- Create a model
- Create a sessionmaker from SQLAlchemy
- Import CRUD functions
- Use CRUD functions and enjoy
Example usage
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 objectget_all
- get all objectsget_all_with_filter
- get all objects with filterget_objects
- get all objects with filter, limit and offsetget_or_create_object
- get or create an objectcreate_object
- create an objectbulk_create
- create multiple objectsupdate_object
- update an objectupdate_or_error
- update an object or raise an errorupdate_object_by_id
- update an object by idupdate_or_create_object
- update or create an objectdelete_object
- delete an objectdelete_object_by_id
- delete an object by idbulk_delete
- bulk delete objectsbulk_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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
hexfrost_simplecrud-0.3.0.tar.gz
(18.1 kB
view hashes)
Built Distribution
Close
Hashes for hexfrost_simplecrud-0.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | aca47b11ddb841e9c76900a53e3eda00ddb079bb203d6c556a417168485db718 |
|
MD5 | fc2c452977dd6b6c5a5a3d457f718b3c |
|
BLAKE2b-256 | 9466953535d066e87b0afb553f369760e2e185fda6c52518514a26a8cdc72dba |
Close
Hashes for hexfrost_simplecrud-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8cd101a6eb5ab65ba733d8824a544792126d6ad1cc2e5024bf83c0552a6c0a5 |
|
MD5 | 100bb3f8071ef01cc2a94fe6cf0f61d8 |
|
BLAKE2b-256 | d3c96c5adbdabae8403caa61472a32240589878777ca84d091b2b2395802db25 |