Skip to main content

Library with operation like (get, create, update, delete) for SQLAlchemy ORM

Project description

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

Project details


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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hexfrost_simplecrud-0.3.0-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file hexfrost_simplecrud-0.3.0.tar.gz.

File metadata

  • Download URL: hexfrost_simplecrud-0.3.0.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.2 Linux/6.5.0-1015-azure

File hashes

Hashes for hexfrost_simplecrud-0.3.0.tar.gz
Algorithm Hash digest
SHA256 aca47b11ddb841e9c76900a53e3eda00ddb079bb203d6c556a417168485db718
MD5 fc2c452977dd6b6c5a5a3d457f718b3c
BLAKE2b-256 9466953535d066e87b0afb553f369760e2e185fda6c52518514a26a8cdc72dba

See more details on using hashes here.

File details

Details for the file hexfrost_simplecrud-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: hexfrost_simplecrud-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.2 Linux/6.5.0-1015-azure

File hashes

Hashes for hexfrost_simplecrud-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a8cd101a6eb5ab65ba733d8824a544792126d6ad1cc2e5024bf83c0552a6c0a5
MD5 100bb3f8071ef01cc2a94fe6cf0f61d8
BLAKE2b-256 d3c96c5adbdabae8403caa61472a32240589878777ca84d091b2b2395802db25

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page