Intuitive interaction with SQLite database
Project description
This project is deprecated since the class Database exists in the library Shared
Litedao
Intuitive interaction with SQLite database
This project is part of the Pyrustic Ecosystem.
Installation | Reference | Shared
Overview
Here is an example of an interaction with an SQL database:
from litedao import Litedao
# Database path (if this file does not exist, it will be created)
DATABASE_PATH = "/home/alex/litedao_test.db"
# SQL code to initialize the database
INIT_SCRIPT = """\
CREATE TABLE friend (username TEXT PRIMARY KEY, email TEXT NOT NULL);
CREATE TABLE enemy (username TEXT PRIMARY KEY, email TEXT NOT NULL)"""
# Insertion SQL code
INSERTION_SQL = """\
INSERT INTO friend (username, email)
VALUES (?, ?), (?, ?)"""
# Selection SQL code
SELECTION_SQL = "SELECT * from friend"
def insert_data(litedao):
# inserts data in the database then returns a boolean
return litedao.edit(INSERTION_SQL, param=("alex", "alex@earth.invalid",
"rustic", "rustic@earth.invalid"))
def select_data(litedao):
# returns the selection
return litedao.query(SELECTION_SQL)
# litedao instance
litedao = Litedao(DATABASE_PATH, init_script=INIT_SCRIPT)
# insert data if this database is newly created
if litedao.is_new:
insert_data(litedao)
selection = select_data(litedao)
tables = litedao.tables()
columns = litedao.columns("friend")
litedao.close() # if you forget to close Litedao, it will close itself at exit
print(selection)
# output: (['username', 'email'], [('alex', 'alex@earth.invalid'), ('rustic', 'rustic@earth.invalid')])
print(tables)
# output: ['friend', 'enemy']
print(columns)
# output: [(0, 'username', 'TEXT', 0, None, 1), (1, 'email', 'TEXT', 1, None, 0)]
Read the reference !
Do you need to store data collections with another simpler paradigm ? Check Shared !
Installation
pip install litedao
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
litedao-0.0.7.tar.gz
(5.9 kB
view details)
Built Distribution
File details
Details for the file litedao-0.0.7.tar.gz
.
File metadata
- Download URL: litedao-0.0.7.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.6.1 requests/2.9.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74ea066877aff86a04d5c8e607b8bf5098cb45cc3d18711fcc151ce9bb62857c |
|
MD5 | f33d77ba51f582bb5d6e4f40995a3171 |
|
BLAKE2b-256 | 546f15be947d39898b253609d521ea57bcc0e6911c88653b4cb101e0cedb3252 |
File details
Details for the file litedao-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: litedao-0.0.7-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.6.1 requests/2.9.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 532ecde63ea5dc17783a35256a525042870d8dc5d63016e8bcb0ca6b57d2afea |
|
MD5 | 5e6bcd4087710c726020652d758d8ac0 |
|
BLAKE2b-256 | f430ff1440f73ec7b7648004c73af11f97425a388c374d12dbcb2e3b450776a6 |