Giter Club home page Giter Club logo

simplecrud's Introduction

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

simplecrud's People

Contributors

kaziamov avatar

Stargazers

Ilya Kuznetsov avatar

simplecrud's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.