Skip to main content

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

  1. 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
  1. Create a SimpleORM instance with the SQLite database filename:
orm = SimpleORM("mydatabase.db")
  1. Create the corresponding table for your model:
orm.create_table(User)
  1. 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
  1. Query all records:
users = orm.get_all(User)
for u in users:
    print(u.id, u.name, u.age)
  1. 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 id attribute for primary keys.

License

This project is released under the MIT License.

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

simple_orm_sqlite-0.0.2.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_orm_sqlite-0.0.2-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file simple_orm_sqlite-0.0.2.tar.gz.

File metadata

  • Download URL: simple_orm_sqlite-0.0.2.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

Hashes for simple_orm_sqlite-0.0.2.tar.gz
Algorithm Hash digest
SHA256 c44c8af62f17363409077f9ebdb73df254d15fd3ed803a1dd35f6739afd9997b
MD5 b87ab602ae52af27c0a7aa9402106cec
BLAKE2b-256 06291ba67ad6e33d3cd68903fe8b913e5eb0d92b9605b0b986d1f7cfcb8124ea

See more details on using hashes here.

File details

Details for the file simple_orm_sqlite-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_orm_sqlite-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5b23126fcb85b5fea61e6a13baf333637b456ca3fcf438bd8f5a733bd7afb5f7
MD5 e49bd4f20383b277726e0b36a2e50d6d
BLAKE2b-256 c0ccb6b1a43e8a0d29120675aee550f80813f3a06405ca6280aa2166a7634109

See more details on using hashes here.

Supported by

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