No project description provided
Project description
Usage
Install:
pip install ormlite
Sample code:
from datetime import datetime
from ormlite import connect_to_sqlite, migrate, 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")
migrate(db)
upsert(db, [Person('me@me.com', 23, "5ft 10in")], update=[])
models = select(Person).where("age = '23'").models(db)
print(list(models))
# Output: [Person(email='me@me.com', age=23, height='5ft 10in', last_seen=datetime.datetime(...))]
db.close()
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.
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
Built Distribution
File details
Details for the file ormlite-0.0.4.tar.gz
.
File metadata
- Download URL: ormlite-0.0.4.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05d12965557dea27036b235909a7345b5e3d797d0715455dca38d4344173d144 |
|
MD5 | e39513fef9d084f1e791ba9c1eaa464b |
|
BLAKE2b-256 | f1d4d69e2b9d6753ab1bd1856c07610cd87044e529316348027d06b3c0463f9f |
Provenance
File details
Details for the file ormlite-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: ormlite-0.0.4-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 549f2c111a6806b60a81902d21c86dafb7a69b6104e42394ce643ec419571f5a |
|
MD5 | 1b938e3edba9d5671570f9ee1de77e3a |
|
BLAKE2b-256 | ccdc796dbe31f34bac392e10e92d47553b391f2ead11e9c4e8c8d779db1fe4aa |