Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pyrustic/litedao
Intuitive interaction with SQLite database
https://github.com/pyrustic/litedao
auto-init dao data database database-access library lightweight pyrustic python sql sqlite
Last synced: about 12 hours ago
JSON representation
Intuitive interaction with SQLite database
- Host: GitHub
- URL: https://github.com/pyrustic/litedao
- Owner: pyrustic
- License: mit
- Created: 2021-06-22T21:57:06.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-03-21T20:35:06.000Z (over 2 years ago)
- Last Synced: 2024-10-16T09:10:56.958Z (about 1 month ago)
- Topics: auto-init, dao, data, database, database-access, library, lightweight, pyrustic, python, sql, sqlite
- Language: Python
- Homepage: https://pyrustic.github.io
- Size: 25.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
**This project is deprecated since the class Database exists in the library [Shared](https://github.com/pyrustic/shared)**
# Litedao
Intuitive interaction with SQLite databaseThis project is part of the [Pyrustic Ecosystem](https://pyrustic.github.io).
[Installation](#installation) | [Reference](https://github.com/pyrustic/litedao/tree/master/docs/reference#readme) | [Shared](https://github.com/pyrustic/shared)
## Overview
Here is an example of an interaction with an SQL database:```python
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", "[email protected]",
"rustic", "[email protected]"))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', '[email protected]'), ('rustic', '[email protected]')])print(tables)
# output: ['friend', 'enemy']print(columns)
# output: [(0, 'username', 'TEXT', 0, None, 1), (1, 'email', 'TEXT', 1, None, 0)]```
Read the [reference](https://github.com/pyrustic/litedao/tree/master/docs/reference#readme) !
Do you need to store data collections with another simpler paradigm ? Check [Shared](https://github.com/pyrustic/shared) !
## Installation
```bash
pip install litedao
```