Skip to main content

No project description provided

Project description

Motivation

I wanted to query a sqlite database, without writing verbose queries. Previously, for work, I've used django's orm for interacting with sql databases. But for a recent small personal project, I wanted a library to interact with sqlite without depending on an entire web framework.

After I deciding to build my own library, I decided to embrace modern python idioms. So my library is built on top of the dataclasses library in the standard lib.

To keep scope small, ormlite only interops with sqlite, not other sql databases. I have no future plans to change this.

Use case

ormlite operates off the principle, that your python source code is the source of truth for the state of the sql tables. Migrations are run in a single step, it checks for differences between your python tables and your sql database. Then it applies sql migrations immediately.

Django & Ruby on Rails, have a separate step whereby migrations are serialized to files. Migrations are thus shared across dev machines, and to production this way.

Since ormlite doesn't do this, it's not suitable for production deployment or teams of devs.

My use case for the library involves running scripts on my local machine, so I enjoy not dealing with the hassle of an evergrowing list of migrations in my repo.

Usage

Install:

pip install ormlite

Sample code:

from datetime import datetime
from ormlite import connect_to_sqlite, model, field, select, upsert

@model('persons')
class Person:
  email: str = field(pk=True)
  age: int
  height: str
  last_seen: datetime = datetime.now()

db = connect_to_sqlite("demo.db")

upsert(db, [Person(23, "5'10\"")], update=[])

models = select(Person).where("age = '23'").models(db)
assert list(models) == [Person(23, "5'10\"")]

db.close()

TODO

  • 100% code coverage
  • github actions to check commits and publish to pypi
  • Fill out README
  • document the api
  • badges:
    • publish to pypi
    • pyright
  • features:
    • optionally serialize migrations
    • interactive migration mode where each operation is approved

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

ormlite-0.0.2-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ormlite-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for ormlite-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 442596d188a08e5d2ca55d496ca408484ddefd6b58791f070ab3084685040539
MD5 330233f4104c162c2c83ee4ff97b490f
BLAKE2b-256 0278ee0bf509d7f13703d45c0bf9670e4489201fb92bb55bf3e41f718abb04fb

See more details on using hashes here.

Provenance

Supported by

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