MiniSLite
MiniSLite is a secure and mini SQLite ORM module.
Install
From Pypi
The script is available on PyPI. To install with pip:
pip install minislite
From Source Code
git clone https://github.com/ahmetkotan/minislite
cd minislite
python setup.py build
python setup.py install
Usage
Create Model
from minislite import MiniSLiteModel
from minislite import DatabaseField
class Person(MiniSLiteModel):
# Only field_type is required
name = DatabaseField(field_type=str, unique=False, not_null=True, auto_increment=False)
last_name = DatabaseField(field_type=str, default="mini")
age = DatabaseField(field_type=int, not_null=False)
# Optionals
table_name = "person"
unique_together = ["name", "last_name"]
Create Database and Add Model
from minislite import MiniSLiteDb
database = MiniSLiteDb("minis.db")
database.add_model(Person)
Create and Update Object
person1 = Person(name="mini", last_name="slite") # not created
person1.age = 1
person1.save() # created
person2 = Person.objects.create(name="mini2", last_name="slite") # created
person2.age = 2
person2.save() # updated
person3 = Person.objects.create(name="mini3", last_name="slite", age=10) # created
person4 = Person.objects.create(name="mini4", last_name="slite", age=20) # created
Update All Objects
Person.objects.update(last_name="slite-updated")
Filter/Get and Delete Object
first_person = Person.objects.first()
last_person = Person.objects.last()
person_objects = Person.objects.filter(last_name="slite-updated")
# or
# person_objects = Person.objects.all()
for person in person_objects:
print(person.name)
person_obj = Person.objects.get(name="mini")
person_obj.delete()
Special Filters
gt,gte,lt,ltefor integer, bool and float fieldscontains,startswith,endswithfor string fields
older_than_10 = Person.objects.filter(age__gt=10)[0]
print(older_than_10.name) # mini4
Delete All Objects
Person.objects.delete(i_am_sure=True)
Clean All Tables or Drop Model
database.clean_tables()
database.drop_model(Person)
Exceptions
from minislite.exceptions import RecordNotFoundError, AlreadyExistsError, DatabaseNotFoundError, \
AreYouSureError, WhereOperatorError
- RecordNotFoundError: If you use
objects.get()and that is not found in database - AlreadyExistsError: Raise this exception when an object creating or saving. Check your
unique=Truefields andunique_togetherfields. - DatabaseNotFoundError: Cannot use TableManager if you don't initialize
MiniSLiteDb() - AreYouSureError: Raise this exception if you want to delete all objects(
objects.delete()) in model. Addi_am_sure=Truearguments. - WhereOperatorError: Raise this exception if you use integer operator for string field. Or vice versa.
Development and Contribution
See; CONTRIBUTING.md
Metadata
Release files for minislite 0.99
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| minislite-0.99.tar.gz | 6.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| minislite-0.99-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.1 kB
Release files / minislite-0.99.tar.gz
| Download URL | minislite-0.99.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e072b196244ee220eb17ad6a4dff9e08a963ed039ff95ba6a1de9a69869972eb
|
|
BLAKE2b-256 checksum How to use checksums |
9942ca3f13dd0a6feeb632b467abc6e2fdf68c205020aeaa33b716acc8033f34
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6
|
Release files / minislite-0.99-py3-none-any.whl
| Download URL | minislite-0.99-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
653b249f3d09232b9346626cb754cfc4d6d82eeb8e54930d8ace36e1838f2f6f
|
|
BLAKE2b-256 checksum How to use checksums |
aed6f394fffa4a95158c3cda84787fb5f2f4030fea3f699d03823723520762e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6
|