Skip to main content

No project description provided

Project description

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:

  pip install skinny_orm

or

  poetry add skinny_orm

Example:

  • Create your model:
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
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)
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)

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

skinny_orm-0.1.2.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

skinny_orm-0.1.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file skinny_orm-0.1.2.tar.gz.

File metadata

  • Download URL: skinny_orm-0.1.2.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.9.13 Windows/10

File hashes

Hashes for skinny_orm-0.1.2.tar.gz
Algorithm Hash digest
SHA256 48a97f66ace895f604a8708a524f50a7414950f4ec65a92216a41000c2d0476a
MD5 bd46774ae01e04c893d3d562c5196640
BLAKE2b-256 90bbeab990dd24f4be731ab51de493ae696dd0de0055c97231b2b92be575e323

See more details on using hashes here.

File details

Details for the file skinny_orm-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: skinny_orm-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.9.13 Windows/10

File hashes

Hashes for skinny_orm-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 eb0e129b88ed7d2f8bf93b7d2f7d0c35d1f21267e765200e3e59f1ba40705e4b
MD5 df07e883b1cea304de4e0cc69baac74c
BLAKE2b-256 8e10ee1496f4088744d57d14462f4a0a88ab9dca370c3938c3d5765690412114

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page