Skip to main content

Mini SQLite ORM

Project description

MiniSLite

MiniSLite is a secure and mini SQLite ORM module.

Install

From Pypi

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")
person1.age = 1
person1.save()

person2 = Person.objects.create(name="mini2", last_name="slite")
person2.age = 2
person2.save()

Update All Objects

Person.objects.update(last_name="slite-updated")

Filter/Get and Delete Object

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()

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, DatabaseNotFound, \
    AreYouSure
  • 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=True fields and unique_together fields.
  • DatabaseNotFound: Cannot use TableManager if you don't initialize MiniSLiteDb()
  • AreYouSure: Raise this exception if you want to delete all objects(objects.delete()) in model. Add i_am_sure=True arguments.

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

minislite-0.9.tar.gz (5.4 kB view details)

Uploaded Source

File details

Details for the file minislite-0.9.tar.gz.

File metadata

  • Download URL: minislite-0.9.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for minislite-0.9.tar.gz
Algorithm Hash digest
SHA256 cb3d83bc5c14d1a7e28187c2330ed1f3bffc77f4d24c73c1932387c415b633fe
MD5 4764817abcaebd1e38b3b354ab5a45fc
BLAKE2b-256 3fdebfd2c844606b8141eb85520bf5040a13b30a27c16ce3de3e9eec54a297f2

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