Skip to main content

A lightweight SQLite Object-Relational Mapping (ORM) library for Python, designed to simplify database interactions and provide an intuitive interface for managing SQLite tables and relationships.

Project description

fresh_orm

Unit-Tests
Published Python Package

Fresh ORM

A lightweight SQLite Object-Relational Mapping (ORM) library for Python, designed to simplify database interactions and provide an intuitive interface for managing SQLite tables and relationships.

Features

  1. Foreign Key Support

    • Foreign keys are mapped to integers (INTEGER type in SQLite), enabling relationships between tables.
  2. Table Creation

    • Automatically generates SQLite tables based on Python model definitions.
  3. CRUD Operations

    • create: Insert new records into a table.
    • update: Update specific fields of existing records.
    • by_id: Retrieve a single record by its primary key.
    • all: Fetch all records from a table.
    • filter: Query records based on specific conditions with support for logical operations.
  4. Seamless Mapping

    • Define models as Python classes and map them directly to SQLite tables without boilerplate code.

Example Usage

from dataclasses import dataclass

from fresh_orm import DbConfig, BaseModel, BaseRepository


@dataclass
class DummyType(BaseModel):
   name: str = None

@dataclass
class Dummy(BaseModel):
   name: str = None
   type: DummyType = None

class DummyTypeRepo(BaseRepository[DummyType]):
   model = DummyType

class DummyRepo(BaseRepository[Dummy]):
   model = Dummy

DbConfig.init_tables([Dummy, DummyType])

dummy_type = DummyTypeRepo.create(DummyType(name='Test Dummy Type'))
dummy: Dummy = DummyRepo.create(Dummy(name='Test Dummy', type=dummy_type))

dummy_from_db: Dummy = DummyRepo.by_id(dummy.id)

assert dummy_from_db.name == dummy.name
assert dummy_from_db.type == dummy.type.id

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

fresh_orm-0.0.2.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

fresh_orm-0.0.2-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fresh_orm-0.0.2.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for fresh_orm-0.0.2.tar.gz
Algorithm Hash digest
SHA256 5792459edbe13b21296e77630f9054f47080a658d8938c6bc36257046d757084
MD5 b6a318f52fa25619dd3099c8b27161c2
BLAKE2b-256 2a6e730df05ebe5364f485e4ddedfd610fd589aad3428e0e826bee664f346187

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fresh_orm-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for fresh_orm-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c8e81f7f936411ebf557481b53db9dbd78d66b3f93221ad11e0c8d5d51e7803a
MD5 ab8ee7dddc3ec50340c77adad54fe37d
BLAKE2b-256 5a5dd71a377ddb313c97e6cf04ff5661744eff664eedbaee1246f790b9a50bf2

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