tiny-orm
A tiny ORM for SQLite.
Install
pip install tiny-orm
Usage
Following a basic tutorial to demonstrate how to use the ORM.
-
Define a
Postmodel in apost.pyfile.# post.py from tiny_orm import Model class Post(Model): text = str # other datatypes: int, float def __init__(self, text): self.text = text
-
Import
Databaseto create a data access object.>>> from tiny_orm import Database >>> db = Database('db.sqlite') # indicating a database file.
-
Import the
Postmodel and link it to the database.>>> from post import Post >>> Post.db = db # see another approach in tests.py
-
Create a post and save it in the staging area (without commit) of database.
>>> post = Post('Hello World').save() >>> print(post.id) # auto generated id 1
-
Change the hello world post and update it in the database.
>>> post = Post.manager().get(id=1) >>> post.text = 'Hello Mundo' >>> post.update() >>> post.text Hello Mundo
-
Commit all staged operations (
saveandupdate) to the database.>>> db.commit()
-
Delete the object and commit.
>>> post.delete() >>> db.commit()
-
Create a manager that can perform CRUD operations in the database.
>>> objects = Post.manager(db)
-
Save and get a post.
>>> objects.save(Post('Hello', 'World')) >>> objects.get(2) # get by id from the staging area {'text': 'World', 'id': 2, 'title': 'Hello'}
-
Close the database without commit the changes
>>> db.close()
-
Get all posts from database.
>>> list(objects.all()) # return a "empty" generator []
Linter
Check code lint:
pip install pylint
pylint orm.py
Contributing
See CONTRIBUTING.
License
The MIT License.
Release files for tiny-orm 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tiny-orm-0.0.1.tar.gz | 4.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tiny_orm-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.7 kB
Release files / tiny-orm-0.0.1.tar.gz
| Download URL | tiny-orm-0.0.1.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4047fda1e3958195a73678a88d52a6aa94e9e2c22b579a085cd8456e4e983d25
|
|
BLAKE2b-256 checksum How to use checksums |
a0423e2443406459ff707955ac388752b2100e2852354b5443f95da30f3cb339
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3
|
Release files / tiny_orm-0.0.1-py3-none-any.whl
| Download URL | tiny_orm-0.0.1-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b930a81fd3f0147be4adc6b49706e40daab5e10c785c0cea5af273c34450091d
|
|
BLAKE2b-256 checksum How to use checksums |
bd5b866f10bce787f3e0be9c90f41ea5506c5d429d9b3b36e9c28a3956c7a6b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3
|