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
  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
  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)
  1. 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.1.tar.gz (3.6 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: simple_orm_sqlite-0.0.1.tar.gz
  • Upload date:
  • Size: 3.6 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.1.tar.gz
Algorithm Hash digest
SHA256 65ae801169fedec4f47c3159ae8a13d6a7985a17e92c7f3f888a0db675bd037e
MD5 ab18cd226899409360fa8c938297543a
BLAKE2b-256 b6636f36446d4a1bf47eba183e3ee74472631b23c881be4b04758cf043ba64d9

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