Basic C.R.U.D for SQLAlchemy models
Project description
SQLAlchemy Crud
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
- Usage Examples
- Getting Started
- Contributing
- Testing
- Compatibility
- License
- Versioning
- Authors and Acknowledgments
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:
- Install the library using the instructions provided in the Installation section.
- Import the necessary modules and create a SQLAlchemy session.
- Use the CRUD functions (
create_model
,get_model
,update_model
,delete_model
, etc.) to perform operations on your SQLAlchemy models. - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sqlalchemy_crud-0.2.2.tar.gz
.
File metadata
- Download URL: sqlalchemy_crud-0.2.2.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-1042-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
8176910c910b8cdcaa4843f2d426d09044a9f9b6e993edd0fedaffe2d2e24b17
|
|
MD5 |
20d7a8501ee382ca7dab394a05760cd9
|
|
BLAKE2b-256 |
27de7b61936ae59b8cca28fb51523788ac346e550c93e3e47b5de90665da8b22
|
File details
Details for the file sqlalchemy_crud-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: sqlalchemy_crud-0.2.2-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-1042-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
9a3e2559e70140eccdf70f9700018a4a6efdd9cb5497a22fa2a8e26f17a10d9c
|
|
MD5 |
d062555387c96a8d7dc2431fd28e64ab
|
|
BLAKE2b-256 |
ec24fe3cc5853486fcf66922ed73723e73d11b1c525c642576d946fa80ce6aed
|