Simple SQL ORM with support for several DB providers
Project description
pythrel
Abstract relational ORM system
WARNING: This is a small project I built mainly to learn how to interface with a few different kinds of SQL database. If you would like to use this in production, no you don't!
Documentation:
Installation:
python3 -m pip install pythrel
Basic Usage:
from pythrel import SqliteDatabase, Pythrel, Record
import secrets
import random
# Create database adapter
db = SqliteDatabase(path="test.db")
db.create_table("customers", {"id": "INTEGER", "customerName": "TEXT", "favorite_number": "REAL"})
db.commit()
# Generate some data
CUSTOMERS = {}
for c in range(500):
CUSTOMERS[c] = {
"id": c,
"customerName": secrets.token_urlsafe(8),
"favorite_number": random.randint(0, 10000)
}
# Insert data
db.query().insert("customers", list(CUSTOMERS.values())).execute()
db.commit()
# Connect DB instance to ORM
orm = Pythrel(db)
# Use database table rows as objects
print(orm.load_columns(Customer, "customers", "*")[0].dict())
orm.create(Customer, "customers", id=-10, customerName="John", favorite_number=-69)
john = orm.load_columns(Customer, "customers", "*", where="id < 0")[0]
print(john)
john.favorite_number = 1000
orm.save(john, key="id")
print(orm.load_query(Customer, orm.query().select("customers", "*").where("id < 0"))[0])
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pythrel-0.1.1.tar.gz.
File metadata
- Download URL: pythrel-0.1.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.0 Linux/6.2.0-1011-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8d9ed3d0ad62815564c18c1f318ce7d4be358a9b79ea1c37c256299f4dae81f
|
|
| MD5 |
c1fef49b188d884addeca94ad90c06c9
|
|
| BLAKE2b-256 |
953db399296be55c0f59da1b0423130ed7aae61622e68d6937a6f167a9571bef
|
File details
Details for the file pythrel-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pythrel-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.0 Linux/6.2.0-1011-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ee08990ee3a6dfa812412f31d65ec3e27c21175b79a6839b358ead3185a7982
|
|
| MD5 |
94dc4023dd32cf5f4441672710951b47
|
|
| BLAKE2b-256 |
23a1ccd68126892d5df8b9ef98a9d3ee04ac6fb9ee0bfd416b9df6cfeb52cde0
|