Helper module for simple sqlite3 use cases
Project description
ansqlite
A python3 module to assist in small sqlite3 database use cases.
Install
python3 -m pip install ansqlite
Usage
from ansqlite import Database, Datatype, PrimaryKeyType, TableColumn
tablename = 'tablename'
db = Database(
database_path='/path/to/database/file.db',
schemas={
tablename: [
TableColumn(
name="timestamp",
datatype=Datatype.INTEGER,
primary_key=PrimaryKeyType.Descending
),
TableColumn(
name="value",
datatype=Datatype.REAL
),
],
'othertablename': [
TableColumn(
name="hash",
datatype=Datatype.TEXT,
),
TableColumn(
name="text",
datatype=Datatype.TEXT
),
],
'anothertablename': [
TableColumn(
name="id",
datatype=Datatype.INTEGER,
primary_key=PrimaryKeyType.Autoincrementing
),
TableColumn(
name="text",
datatype=Datatype.TEXT
),
],
}
)
db.insert_data(
table_name=tablename,
data=[
{'timestamp': 1699304400, 'value': 4.496},
{'timestamp': 1699300800, 'value': 6.812},
{'timestamp': 1699297200, 'value': 7.847},
{'timestamp': 1699293600, 'value': 9.548}
]
)
db.execute_and_commit(
sql=f'UPDATE {tablename} SET value=1.00 WHERE timestamp=1699300800;',
errmsg='Failed to set value'
)
rows = db.execute_and_fetchall(
sql=f'SELECT * FROM {tablename} where timestamp >= 1699297200 and timestamp < 1699304400 limit 10;',
errmsg='Failed to retrieve data',
result_model=db.get_model(tablename),
)
print(rows)
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
ansqlite-0.4.2.tar.gz
(4.5 kB
view details)
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 ansqlite-0.4.2.tar.gz.
File metadata
- Download URL: ansqlite-0.4.2.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75751074b6e80de73f2aaffe0961883c064a3edea2cf050bda55c2fa4aacc7d4
|
|
| MD5 |
baef6c1156a686070bb543e05dcd47ec
|
|
| BLAKE2b-256 |
a633c549eb32eccaeaa31719a77d5958c980cbc0ac4b267ac798953498d2b351
|
File details
Details for the file ansqlite-0.4.2-py3-none-any.whl.
File metadata
- Download URL: ansqlite-0.4.2-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68384902aebb03c8fde561c81aab9b125447bc93e3ffd7fa1b669f7cc2159583
|
|
| MD5 |
1714f056a87ed96180e0b728585d315c
|
|
| BLAKE2b-256 |
be872fbba3e21522066ad459a1c05dfb26ea0919a202d9ad49c34100aafad250
|