Basic Orm for sqlite
Project description
SimpleORM
SimpleORM is a lightweight and easy-to-use Object-Relational Mapping (ORM) utility for Python built on top of SQLite. It provides basic CRUD (Create, Read, Update, Delete) operations by mapping Python classes directly to SQLite tables, simplifying database interactions without requiring complex setup.
Features
- Automatically creates SQLite tables based on Python class annotations.
- Insert Python objects into the database.
- Retrieve all or single records as Python objects.
- Delete records by object instance or ID.
- Supports basic Python types:
int,str,float.
Installation
No external dependencies are required besides Python's built-in sqlite3 module. Just include the SimpleORM class in your project.
Usage
- Define your data model as a Python class with type annotations.
class User:
id: int
name: str
age: int
or
@dataclass
class User:
id: int = field(init=False)
name: str
age: int
- Create a
SimpleORMinstance with the SQLite database filename:
from simple_orm import SimpleORM
orm = SimpleORM("mydatabase.db")
- Create the corresponding table for your model:
orm.create_table(User)
- Insert objects:
user = User()
user.name = "Alice"
user.age = 25
orm.insert(user)
print(user.id) # Auto-generated ID
if usage dataclasses
user = User(name='Alice', age=25)
# ID is auto-generated
- Query all records:
users = orm.get_all(User)
for u in users:
print(u.id, u.name, u.age)
- Query a single record by ID:
user = orm.get_one(User, 1)
if user:
print(user.name, user.age)
if you used dataclasses, make only
if user:
print(user)
because dataclasses add repr 7. Delete records:
orm.delete(user) # Delete by object
orm.delete_by_id(User, 2) # Delete by ID
orm.delete_all(User) # Delete all records for the class
Limitations
- Supports only simple types (
int,str,float). - Does not support complex queries, relationships, or migrations.
- Assumes classes have an
idattribute for primary keys.
License
This project is released under the MIT License.
how to contribute?
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 simple_orm_sqlite-0.0.3.tar.gz.
File metadata
- Download URL: simple_orm_sqlite-0.0.3.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df454944e7a8cc8df5f6c6e919dcf0bf1152c7ff9a84076f38aadfc0ee1334a1
|
|
| MD5 |
1b6fc583e99fcae322f02a74fb5edc60
|
|
| BLAKE2b-256 |
455e9a7702aee4dad12b5fd0bb0bd70426e9bb7278fdebf785c9ff59a8205e74
|
File details
Details for the file simple_orm_sqlite-0.0.3-py3-none-any.whl.
File metadata
- Download URL: simple_orm_sqlite-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5200c8a9f904a23b92b73308d4ec2cfe5f96565c5648538af9bf53f419e31ddb
|
|
| MD5 |
6b283a915903401043abb44511e3346c
|
|
| BLAKE2b-256 |
b5dc4c46a33a9622127c91e367defae382eff164af576023578b3a5b4e522c62
|