Skip to main content

Basic C.R.U.D for SQLAlchemy models

Project description

SQLAlchemy Crud

.github/workflows/poetry-pytest.yml codecov

sqlalchemy-crud is a Python library that takes the pain out of performing common CRUD operations on SQLAlchemy models. It provides a simple and intuitive interface to create, read, update, and delete records in your database.

Table of Contents

Installation

You can easily install sqlalchemy-crud using Poetry, a dependency management tool for Python:

$ poetry add sqlalchemy-crud

Make sure you have Python 3.8, 3.9, 3.10, or 3.11 installed.

Usage Examples

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy_crud import crud

from my_app.models import MyModel

# Set up the SQLAlchemy session
engine = create_engine("sqlite:///database.db")
Session = sessionmaker(bind=engine)
db = Session()

# Create a new object
model = crud.create_model(db, MyModel, schema={"name": "John Doe"})

# Retrieve all objects
models = crud.get_models(db, MyModel)

# Retrieve an object by ID
model = crud.get_model(db, MyModel, model_id=1)

# Retrieve objects by a specific attribute
models = crud.get_models_by_attribute(db, MyModel, attribute="name", value="John Doe")
model = crud.get_model_by_attribute(db, MyModel, attribute="uuid", value="123e4567-e89b-12d3-a456-426614174000")

# Update an object
model = crud.update_model(db, MyModel, model_id=1, schema={"name": "Jane Doe"})

# Delete an object
crud.delete_model(db, MyModel, model_id=1)

Getting Started

To get started with sqlalchemy-crud, follow these steps:

  1. Install the library using the instructions provided in the Installation section.
  2. Import the necessary modules and create a SQLAlchemy session.
  3. Use the CRUD functions (create_model, get_model, update_model, delete_model, etc.) to perform operations on your SQLAlchemy models.
  4. Refer to the Usage Examples section for more detailed examples and code snippets.

Contributing

I welcome contributions from the community! If you'd like to contribute to sqlalchemy-crud, please follow the guidelines outlined in CONTRIBUTING.md.

Testing

To run the tests for sqlalchemy-crud, execute the following command:

$ poetry run pytest

Compatibility

sqlalchemy-crud is compatible with Python 3.8, 3.9, 3.10, and 3.11. It works with SQLAlchemy 1.3.19 up to but excluding (<) 2.

License

This library is released under the MIT License. See the LICENSE file for more details.

Versioning

this project follows semantic versioning for sqlalchemy-crud releases.

Authors and Acknowledgments

sqlalchemy-crud is maintained by Clayton Black.

Thank you to all the contributors to open-source software.
Not only do I use a lot of it, but I learn a lot from it as well.

I hope you find sqlalchemy-crud useful in your projects and appreciate your feedback and contributions!

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

sqlalchemy_crud-0.2.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

sqlalchemy_crud-0.2.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy_crud-0.2.1.tar.gz.

File metadata

  • Download URL: sqlalchemy_crud-0.2.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.0 Linux/5.15.0-1041-azure

File hashes

Hashes for sqlalchemy_crud-0.2.1.tar.gz
Algorithm Hash digest
SHA256 1931f4b3a295e64ff2284fb4b05dea34beaa081039db8143627c96f24cb850a4
MD5 c95e815dd70f471db0f77797111d95bb
BLAKE2b-256 6aa2f6ccb8e2bcd254526e5435a41dc62ffd8e63452429595585b231037a904f

See more details on using hashes here.

File details

Details for the file sqlalchemy_crud-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: sqlalchemy_crud-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.0 Linux/5.15.0-1041-azure

File hashes

Hashes for sqlalchemy_crud-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f7e0247db38e1db4393a87bf89eb2319085a44806d94a202b106f875d216b8e0
MD5 00f8f90c278d820dcd5c78659373e29a
BLAKE2b-256 bf2c527b4c1f6bb94364614093876ee59bc33c85365c4f534d9d51648ef22529

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