crudal-0.3.1
توضیحات
CRUD operations for SQLAlchemy models
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | crudal-0.3.1 |
| نام | crudal |
| نسخه کتابخانه | 0.3.1 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | andrewsap |
| ایمیل نویسنده | andrewsapw@gmail.com |
| آدرس صفحه اصلی | - |
| آدرس اینترنتی | https://pypi.org/project/crudal/ |
| مجوز | MIT |
# CRUDAL
Ready to use CRUD methods for SQLAlchemy models. Both *Sync* and *Async*
```
pip install crudal
```
# Examples
## Sync
### Model initialization
```python
from crudal import DeclarativeCrudBase
from sqlalchemy import Integer, String, create_engine
from sqlalchemy.orm import Mapped, mapped_column, sessionmaker
engine = create_engine("sqlite://")
SessionLocal = sessionmaker(engine, expire_on_commit=False)
class User(DeclarativeCrudBase):
__tablename__ = "person"
__session__ = sessionmaker(engine, expire_on_commit=False)
id: Mapped[int] = mapped_column(Integer, primary_key=True)
name: Mapped[str] = mapped_column(String, nullable=False)
DeclarativeCrudBase.metadata.create_all(bind=engine)
```
### Add new item
```python
user = User(name="Andrew")
user.add()
```
### Find item
Find all users with name equals *Andrew*
```python
users_found = User.find(name="Andrew")
for u in users_found:
assert u.name == "Andrew"
```
### Update item
Change name of all users with name *Andrew* to *John*
```python
User.update(session=session, values=dict(name="John"), name="Andrew")
```
### Delete item
```python
User.delete(name="John")
```
## Async
```python
from crudal import DeclarativeCrudBaseAsync
from sqlalchemy import Integer, String, create_engine
from sqlalchemy.orm import Mapped, Session, mapped_column
class User(DeclarativeCrudBaseAsync):
__tablename__ = "person"
id: Mapped[int] = mapped_column(Integer, primary_key=True)
name: Mapped[str] = mapped_column(String, nullable=False)
```
## Find
```python
with Session(bind=engine) as session:
p = User(name="Andrew")
p.add(session=session)
p2 = User(name="Bob")
p2.add(session=session)
# find person with name "Andrew"
andrew = User.find(session=session, name="Andrew")
all_users = User.all(session=session)
for u in all_users:
print(u.name)
```
###
نیازمندی
| مقدار | نام |
|---|---|
| >=2.0.7,<3.0.0 | SQLAlchemy[asyncio] |
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.8,<4.0 | Python |
نحوه نصب
نصب پکیج whl crudal-0.3.1:
pip install crudal-0.3.1.whl
نصب پکیج tar.gz crudal-0.3.1:
pip install crudal-0.3.1.tar.gz