simple single file dao for sqlite
Project description
SqliteDao
A simplified DAO for SQL abstraction for personal projects. All in one file.
pip install sqlitedao
Examples
Create Table easily:
dao = SqliteDao.get_instance(DB_PATH)
create_table_columns = {
"name": "text",
"position": "text",
"age": "integer",
"height": "text"
}
dao.create_table(TEST_TABLE_NAME, create_table_columns)
Or with a bit more control:
columns = ColumnDict()
columns\
.add_column("name", "text", "PRIMARY KEY")\
.add_column("position", "text")\
.add_column("age", "integer")\
.add_column("height", "text")
create_table_indexes = {
"name_index": ["name"]
}
dao.create_table(TEST_TABLE_NAME, columns, create_table_indexes)
INSERT:
lebron = {"name": "LeBron James", "position": "SF", "age": 35, "height": "6-8.5"}
kobe = {"name": "Kobe Bryant", "position": "SG", "age": 41, "height": "6-6"}
jordan = {"name": "Michael Jordan", "position": "SG", "age": 56, "height": "6-6"}
dao.insert_rows(TEST_TABLE_NAME, [lebron, kobe, jordan])
READ:
result = dao.search_table(TEST_TABLE_NAME, {"position": "SG"})
[{'name': 'Kobe Bryant', 'position': 'SG', 'age': 41, 'height': '6-6'},
{'name': 'Michael Jordan', 'position': 'SG', 'age': 56, 'height': '6-6'}]
Or with more operators:
result = dao.search_table(TEST_TABLE_NAME, SearchDict().add_filter("age", 40, operator="<"))
UPDATE:
dao.update_many(TEST_TABLE_NAME, [{"age": 30}, {"age": 40}], [{"name": "A"}, {"name": "B"}])
update_row, update_rows is also available with slightly different functionality.
DELETE:
dao.delete_rows(TEST_TABLE_NAME, {"position": "SG"})
Same for update and deletion.
Create classes inheriting TableItem easily and deal with even less code,
dao.insert_item(item)
dao.insert_items(items)
dao.update_item(changed_item)
dao.update_items(changed_items)
dao.find_item(item_with_only_index_populated)
...
see test/item_test.py for example.
Helpers
-
SearchDict: allow more comparators than "="
-
ColumnDict: allow 'primary key && not null' to columns.
- 1, 2 not needed for full functions
- TableItem: baseclass for python items <-> db row connection.
TODO
Add support for pagination (offsets)
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 sqlitedao-0.1.1.tar.gz.
File metadata
- Download URL: sqlitedao-0.1.1.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f142e707f3a0e63c5dd14cdbef6addffbd6c8e04b5410a9539c8a40495dd9966
|
|
| MD5 |
b46c5cbbcf50cadb40ca695b7a0d4d2b
|
|
| BLAKE2b-256 |
467af390fe434c0ce031891bd76c80438fe5f5af9e29e719bcf110294560b67b
|
File details
Details for the file sqlitedao-0.1.1-py3-none-any.whl.
File metadata
- Download URL: sqlitedao-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
466c09a4ec1522cbe82cd53994ed2dd40596d9572d0a3145791c178939c2b9fc
|
|
| MD5 |
97842491ad861ffa69baa8c89534ca7f
|
|
| BLAKE2b-256 |
17c1981ddaf74a1cc388296e0430b09cfc001dad0e9960cdff7db1eaf289e0d4
|