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.0.tar.gz (4.0 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.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqlalchemy_crud-0.2.0.tar.gz
  • Upload date:
  • Size: 4.0 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.0.tar.gz
Algorithm Hash digest
SHA256 774cb589ebae996aff483d2e879103ebfc96889cee8af5b22253508b6fd3b2e0
MD5 823a22ace93d9e3b33ba5aaaf9d2ec85
BLAKE2b-256 ab7af754ce3cd18a03715238b9efd17a8fc65386745ee3927dc0f10c1e4d7bc2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlalchemy_crud-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de6261d4f141f3c98a8bb106ed5b755199df91cc2c50f993ffb33292a8b68e65
MD5 607be64b253993daa6130df74ab88040
BLAKE2b-256 8046835731f0bd91a9f3d7c55b540353852c73164d73bc1fed6538a6cd5376b5

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