Package: sa-modelcrud
SQLAlchemy Model CRUDModel CRUD manager to handle databases with asynchronous SQLAlchemy sessions.Source code:https://github.com/lucaslucyk/sa-model-crudPackage:https://pypi.org/project/sa-modelcrudDocumentation: Coming soon.Project Status⚠️Warning: This project is currently indevelopment phase.This project is in an early stage of development and may contain bugs. It is not recommended for use in production environments.Why usesa_crudmodel?🚀Fast to code: Increase the speed to develop integrations features.❌Fewer bugs: Reduce human (developer) induced errors.💡Intuitive: Great editor support. Completion everywhere. Less time debugging.🤓Easy: Designed to be easy to use and learn. Less time reading docs.〽️Short: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs.RequirementsPython 3.8+SQLAlchemy Model CRUD stands on the soulders of giants:SQLAlchemyfor the database parts.Pydanticfor the data parts.Installation$pipinstallsa-modelcrudExampleDatabase Model prepareCreate a database model with:fromsqlalchemy.ormimportMapped,mapped_columnfromsa_modelcrud.modelsimportModelBase,TimestampclassSample(Timestamp,ModelBase):# ModelBase contains id and uid propertiesemail:Mapped[str]=mapped_column(nullable=True,unique=True)Create schemasfromtypingimportOptionalfromuuidimportUUIDfrompydanticimportBaseModelclassSampleBase(BaseModel):id:Optional[UUID]=Noneemail:Optional[str]=NoneclassSampleCreate(SampleBase):...classSampleUpdate(SampleBase):...Create CRUDfromsa_modelcrudimportCRUDBaseclassCRUDSample(CRUDBase[Sample,SampleCreate,SampleUpdate]):model=Samplesamples=CRUDSample()Create sessionfromsqlalchemy.ext.asyncioimport(AsyncSession,create_async_engine,async_sessionmaker)DB_URI="sqlite+aiosqlite:///./db.sqlite3"async_engine:AsyncEngine=create_async_engine(DB_URI,future=True,connect_args={"check_same_thread":False})AsyncSessionLocal:AsyncSession=async_sessionmaker(bind=async_engine,class_=AsyncSession,expire_on_commit=False)Use the CRUDasyncwithAsyncSessionLocal()asdb:data=SampleCreate(email="sample@sample")# save data into databasesample_obj=awaitsamples.create(db=db,element=data)General CRUD MethodsAll inherited CRUDBase instances have the following methods:.get(..., id): Get row from model by uid..get_or_raise(..., id): Try to get row from model by uid. Raise if not object found..list(...): Get multi items from database..filter(..., whereclause): Get items from database usingwhereclauseto filter..find(..., **kwargs): Find elements with kwargs..find_one(..., **kwargs): Find an element with kwargs..create(..., element): Create an element into database..bulk_create(..., elements): Create elements into database..update(..., obj, data): Update a database obj with an update data schema..delete(..., id): Delete an item from database.TODO:Paginate results of methodslist,filterandfind.Add default values foroffsetandlimiton paginated methods.Add support for Sync Sessions.Create complete documentation inReadthedocs.Contributions and FeedbackI would love to receive contributions and feedback! If you'd like to get involved, please contact me through one of the contact methods in myProfile.LicenseThis project is licensed under the terms of the MIT license.