Skip to main content

This is a python package that makes it easier to work with sqlite

Project description

Sqlite middleware

This package removes all the annoying boilerplate code you have to write when using sqlite3. Instead, use the methods this package provides, and easily manage your sqlite database in your python project.

Db class:

All the functionality of this package is in the Db class. When creating a new instance of this class, you should specify following parameters:

  • database: (str) name of the sqlite file

Example usage:

db = Db("demo.db")

When an instance of Db is deleted, the __del__ magic method will close the connection.

Methods

Here are all the methods that the Db class provides:

Select all

This method will retrieve and return all objects of a certain class from the sqlite database.

Parameters:

  • cls: (Class) class of the objects you want to retrieve

Example usage:

db.select_all(Person)

Select by id

This method will retrieve and return an object with certain id and class from the database.

Parameters:

  • cls: (Class) class of the object you want to retrieve
  • id: (int) id of the object you want to retrieve

Example usage:

db.select_by_id(Person, 2)

Create table

This method will create a table in the database for objects of a certain class.

Parameters:

  • object: (Instance) instance of the class you want to create a new table for.

Example usage:

db.create_table(Person())

Save object

This method will save an object in the database.

It will also create a table if it doesn't exist yet.

Parameters:

  • object: (Instance) object you want to save in the database.

Example usage:

person = Person("John Doe")
db.save_object(person)

Update object

This method will update an existing object in the database.

Parameters:

  • id: (int) id of the object you want to update.
  • object: (Instance) object containing new values you want to save in the database.

Example usage:

person = Person("John Doe")
db.save_object(person) # Say this is the first person, and gets id 1

person.set_name("Michael Myers")
db.update_object(1, person)

Delete object

This method will delete an object from the database.

Parameters:

  • cls: (Class) class of the object you want to delete.
  • id: (int) id of the object you want to delete

Example usage:

person = Person("John Doe")
db.save_object(person) # Say this is the first person, and gets id 1

db.delete_object(Person, 1)

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

sqlite_middleware-0.0.2.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqlite_middleware-0.0.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file sqlite_middleware-0.0.2.tar.gz.

File metadata

  • Download URL: sqlite_middleware-0.0.2.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for sqlite_middleware-0.0.2.tar.gz
Algorithm Hash digest
SHA256 baa3903d6bec6e9665a8b8fc5eebbb13fab71f54608dfdb7ee0fba363864bdd3
MD5 e559639a096b9d824d4d5568f63da667
BLAKE2b-256 e0b15d580bcde42e17d6115819efe6c0c20c4231f7dcd13cc78539693313b894

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlite_middleware-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4263cb7859bee8a120be1cb175b19fa600df319518e3f1aa03ce8eeb63187128
MD5 e1ecdf8c9bc352198e2ed325c0a7b2eb
BLAKE2b-256 ad9aab006ab6999d7d560dce39b70a7b2a9dd0b871a13ae39fa512825e5c3b6f

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