https://github.com/mayasmess/skinny-orm
⚡️"Skinny ORM" - a Python package for data persistence using dataclasses
https://github.com/mayasmess/skinny-orm
Last synced: 11 months ago
JSON representation
⚡️"Skinny ORM" - a Python package for data persistence using dataclasses
- Host: GitHub
- URL: https://github.com/mayasmess/skinny-orm
- Owner: MayasMess
- Created: 2023-07-08T09:40:34.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-05-16T08:39:06.000Z (about 2 years ago)
- Last Synced: 2025-06-26T01:05:38.793Z (12 months ago)
- Language: Python
- Homepage:
- Size: 23.4 KB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.MD
Awesome Lists containing this project
README
# Skinny ORM
"Skinny ORM" - a lightweight Python package that simplifies data storage, manipulation, and retrieval from a SQLite (maybe others later) database using Python dataclasses.
It's not really a "Relational Mapper". It's just a simple way to persist data.
Installation:
-
```shell script
pip install skinny_orm
```
or
```shell script
poetry add skinny_orm
```
Example:
-
- Create your model:
```python
from dataclasses import dataclass
from datetime import datetime
@dataclass
class User:
id: int
name: str
age: int
birth: datetime
percentage: float
```
- Create a connection et an "orm" object
```python
import sqlite3
from skinny_orm.orm import Orm
connection = sqlite3.connect('database.db')
orm = Orm(connection)
```
- And Voila (no need to create tables. if they don't exist, it will create them automatically)
```python
users = [
User(id=1, name='Naruto', age=15, birth=datetime.now(), percentage=9.99),
User(id=2, name='Sasuke', age=15, birth=datetime.now(), percentage=9.89),
User(id=3, name='Sakura', age=15, birth=datetime.now(), percentage=9.79),
]
# Bulk insertions (if the table "User" does not exist, it will create it)
orm.bulk_insert(users)
# Selections (always end with .first() or .all() )
naruto: User = orm.select(User).where(User.name == 'Naruto').first()
the_boys: list[User] = orm.select(User).where((User.name == 'Naruto') | (User.name == 'Sasuke')).all()
# Update data by setting specific fields
orm.update(User).set(User.age == 30).where(User.id == 1)
# Or you can simply update the object with all the fields
naruto.age = 30
orm.update(naruto).using(User.id)
# Bulk update objects
users_20_year_later = [
User(id=1, name='Naruto', age=35, birth=datetime.now(), percentage=9.99),
User(id=2, name='Sasuke', age=35, birth=datetime.now(), percentage=9.89),
User(id=3, name='Sakura', age=35, birth=datetime.now(), percentage=9.79),
]
orm.bulk_update(users_20_year_later).using(User.id)
```