Sqlite ORM
Sqlite orm modeled after django orm
Quick Demo
from sqlite import SqliteDatabase
db = SqliteDatabase(":memory:")
# Catch all errors
@db.on("error")
def _(err):
raise err
class Session(db.Model):
sid: int # Type Number
data: str # Type Text
class User(db.Model):
name: str
age: int
password: bytes # Type blob
# Instance method
def verify_password(self, password):
return self.password == password
class Note(db.Model):
name: str # Not null field
body: str = '' # Default field
user: User # Foreign Key assignment
users: list[User] # Many to one keys
# Get or create entry
bob = User(name="Bob", age=7, password=b"MyAwesomePassword")
# Check if entry exists
print(bob.id != None)
# Update entry
bob.age = (bob.age + 1)
# Save entry
bob.save()
# Call nstance method
print(bob.verify_password(b""))
# Get multiple entries
notes = Note.objects.get(user=bob)
Authentication and Authorization model demo
from sqlite import SqliteDatabase
from sqlite.columns import *
from sqlite.files import FileSystemStorage
database = SqliteDatabase("./db.sqlite")
@database.on('error')
def error(e):
raise e
# For easier access to files and folders
# Call 'create' to create directory if not exists
store = FileSystemStorage(directory="./media").create()
# Go to subdirectory
# Sames api as FileSystemStorage object
uploads = store["uploads"].create()
class Role(database.Model):
role: str = SelectColumn(options=["admin", "editor", "user", "superuser"])
level: int = IntegerColumn(null=False, min=1, max=100)
def __str__(self):
return f"[{self.id}] role -> {self.role}: level -> {self.level}"
class Meta:
table_name = "auth_role"
class User(database.Model):
username: str
email_addr: str = EmailColumn(
label="Email Address",
helper_text="User's email address: '@' must be present",
unique=True
)
desc: str = Column(
label="Description",
helper_text="Description of the user"
)
creation_date: datetime = DateTimeColumn(null=False)
image: str = ImageColumn(
extensions=["jpg", "png"],
store=uploads, default="default.png",
label="Image"
)
last_login: datetime = DateTimeColumn()
hash: bytes = BytesColumn(null=False)
is_active: bool = BooleanColumn()
@property
def tag(self):
return f"@{self.username}".lower()
def __str__(self):
return f"[{self.id}] username -> {self.username}"
class Meta:
table_name = "auth_users"
class PendingReg(database.Model):
code: str
email_addr: str = EmailColumn(label="Email Address")
desc: str = Column(editor="full", label="Description")
hash: bytes = BytesColumn(null=False)
username: str = Column(null=False)
creation_date: datetime = DateTimeColumn(null=False, label="Date Created")
class Meta:
table_name = "auth_pending_registrations"
class Token(database.Model):
tokenid: str
last_used: datetime = DateTimeColumn(null=True)
is_expired = BooleanColumn(default=False)
usage_amount: int = IntegerColumn(default=0)
usage_limit: int = IntegerColumn()
user = ForeignKeyColumn(User)
value: str = Column(null=False)
creation_date: datetime = DateTimeColumn(null=False, label="Created")
expiry_date: datetime = DateTimeColumn(null=True)
@property
def owner(self):
return User.objects.get(id=self.user_id)
class Meta:
table_name = "auth_tokens"
class AuthAttempts(database.Model):
ip_address: str = Column(null=False)
user_agent: str = Column(null=False)
token: str = Column(null=False)
created_at = DateTimeColumn()
class Meta:
table_name = "auth_activation_attempts"
class Permissions(database.Model):
name: str = Column(null=False)
description: str = Column(null=False)
class Meta:
table_name = 'auth_permissions'
class UsersPermissions(database.Model):
user = ForeignKeyColumn(User)
permission = ForeignKeyColumn(Permissions)
class Meta:
table_name = 'auth_users_permissions'
class Groups(database.Model):
name: str = Column(null=False)
description: str = Column(null=False)
class Meta:
table_name = 'auth_groups'
class GroupsUsers(database.Model):
user: int = ForeignKeyColumn(User)
group: int = ForeignKeyColumn(Groups, name="user_group")
class Meta:
table_name = 'auth_groups_users'
class GroupsPermissions(database.Model):
group = ForeignKeyColumn(Groups, name="user_group")
permission = ForeignKeyColumn(Permissions)
class Meta:
table_name = 'auth_groups_permissions'
Metadata
Release files for sqlite3-orm 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sqlite3_orm-1.0.0.tar.gz | 22.9 kB | Without provenance | Details for sqlite3_orm-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sqlite3_orm-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for sqlite3_orm-1.0.0-py3-none-any.whl |
Total release size: 48.2 kB
Release files / sqlite3_orm-1.0.0.tar.gz
| Download URL | sqlite3_orm-1.0.0.tar.gz |
|---|---|
| Size | 22.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5fcf29677ebed41a5a6d0f61f8e2a77941ab6463097cfe99aa7e77e2d7831545
|
|
BLAKE2b-256 checksum How to use checksums |
3404a3aeb21f5b6d93f06d4a185a72121507c2e2790002b7ef6449b9fce2f2de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.19
|
Release files / sqlite3_orm-1.0.0-py3-none-any.whl
| Download URL | sqlite3_orm-1.0.0-py3-none-any.whl |
|---|---|
| Size | 25.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e0b856368dd03ac9ec5274b0e946b5daee6702aad9059aed25b9022c9a658f86
|
|
BLAKE2b-256 checksum How to use checksums |
2476c11d52b037edb26032943bf5c70189d0801956d391c4ffb64c5569a3fbc0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.19
|
Security for sqlite3-orm 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.