sqlite_orm is a dependency less orm for sqlite database built with and for python
Project description
SQLite ORM
A lightweight Django-like ORM for SQLite with full type support and thread safety.
Quick Start
1. Define Models
from sqlite_orm.db import BaseModel
from sqlite_orm.fields import CharField, IntegerField, BooleanField, DateTimeField, ForeignKey
class User(BaseModel):
id = IntegerField(primary_key=True)
username = CharField(max_length=50, unique=True)
email = CharField(max_length=100, unique=True)
is_active = BooleanField(default=True)
created_at = DateTimeField(auto_now_add=True)
table_name = 'users'
class Post(BaseModel):
id = IntegerField(primary_key=True)
title = CharField(max_length=200)
content = TextField()
author_id = ForeignKey(User)
table_name = 'posts'
# Initialize
User.init_db('app.db')
Post.init_db('app.db')
# Create
user = User.create(username="john", email="john@example.com")
post = Post.create(title="Hello", content="World", author_id=user.id)
# Read
user = User.get(username="john")
posts = Post.objects.filter(author_id=user.id).all()
# Update
user.username = "john_updated"
user.save()
# Delete
user.delete_instance()
## Field lookup
User.objects.filter(id__gt=5) # Greater than
User.objects.filter(username__contains="sm") # Contains
User.objects.filter(username__icontains="SM") # Case-insensitive
User.objects.filter(username__in=["a","b"]) # In list
User.objects.filter(username__startswith="j") # Starts with
User.objects.filter(username__ne="admin") # Not equal
Model Methods
Model.create(**kwargs) → Model - Create new record
Model.get(**filters) → Model - Get single record
Model.all() → List[Model] - Get all records
Model.filter(**filters) → QuerySet - Start filtered query
Model.update(filters, values) → int - Bulk update
Model.delete(**filters) → int - Bulk delete
Model.count(**filters) → int - Count records
Model.exists(**filters) → bool - Check existence
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
sqlite_orm_simple-0.1.0.tar.gz
(10.4 kB
view details)
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 sqlite_orm_simple-0.1.0.tar.gz.
File metadata
- Download URL: sqlite_orm_simple-0.1.0.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
297168252c7a467410beff5b81d6ab3cd2be2aed553ec8975b977e56f2aede62
|
|
| MD5 |
4ea1dae52593fa43280fcb89526a2c5e
|
|
| BLAKE2b-256 |
960602f33dcae2c0f12990b8a91826fdac15c9187208b9387ee5adb1a2efb5b8
|
File details
Details for the file sqlite_orm_simple-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sqlite_orm_simple-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
140543da35b7c43f9b46efa16fd4e8aa4bf48342900958f569d15a64afd67893
|
|
| MD5 |
48101ce2c65ac6f539232d603ddbb70c
|
|
| BLAKE2b-256 |
83a8e351c55fe1151891e36c548a2891b808f9767b14665c7f41eca18ae7af7b
|