Skip to main content

Maintainability Test Coverage flake8

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

  1. Create a model
  2. Create a sessionmaker from SQLAlchemy
  3. Import CRUD functions
  4. 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 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

Release files for hexfrost-simplecrud 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hexfrost-simplecrud 0.3.0
File Size Uploaded
hexfrost_simplecrud-0.3.0.tar.gz 18.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hexfrost-simplecrud 0.3.0
File Interpreter ABI Platform
hexfrost_simplecrud-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 37.4 kB

Release files / hexfrost_simplecrud-0.3.0.tar.gz

Download URL hexfrost_simplecrud-0.3.0.tar.gz
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
aca47b11ddb841e9c76900a53e3eda00ddb079bb203d6c556a417168485db718
BLAKE2b-256 checksum
How to use checksums
9466953535d066e87b0afb553f369760e2e185fda6c52518514a26a8cdc72dba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.2 Linux/6.5.0-1015-azure

Release files / hexfrost_simplecrud-0.3.0-py3-none-any.whl

Download URL hexfrost_simplecrud-0.3.0-py3-none-any.whl
Size 19.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a8cd101a6eb5ab65ba733d8824a544792126d6ad1cc2e5024bf83c0552a6c0a5
BLAKE2b-256 checksum
How to use checksums
d3c96c5adbdabae8403caa61472a32240589878777ca84d091b2b2395802db25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.2 Linux/6.5.0-1015-azure

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page