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
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlite_middleware-0.0.1.tar.gz.
File metadata
- Download URL: sqlite_middleware-0.0.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1eac6dfd19e7f106a4d97926edc05d2f7ce754e80bbe125cb59cbaa2ddc1b06
|
|
| MD5 |
ec2116a72f8dc946ce5ac5ce96b47e65
|
|
| BLAKE2b-256 |
32945f42b57b28df9c69bab436d4553ad99e1b26a1ab2526fb01d07c12e74bef
|
File details
Details for the file sqlite_middleware-0.0.1-py3-none-any.whl.
File metadata
- Download URL: sqlite_middleware-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dca14c69963028e6d5d29f445e42e49544b00aa9a0bdecb23c55639c3abc42f4
|
|
| MD5 |
337ccf557d850f75c22eee58caae2ddb
|
|
| BLAKE2b-256 |
ba9b8fbe0e0fed07f196b3bf9eaccc3ac8c755697d2989e53b5fbad8ed00f6cd
|