Conversion between a sqlite3 table and a python dictionary.
Project description
aiosqlitedict is a Python package that provides fast, flexible and expressive data structures designed to make working with "relational" or "labeled" data both easy and intuitive.
Main Features:
- Easy conversion between sqlite table and Python dictionary and vice-versa.
- Get values of a certain column in a Python list.
- Order your list ascending or descending.
- Choose any number of columns to your dict, which makes it faster for your dict to load instead of selecting all.
Installation
py -m pip install -U aiosqlitedict
Getting Started
We start by connecting our database along with the table name and the reference column
from aiosqlitedict.database import Connect
DB = Connect("database.db", "my_table_name", "user_id")
Make a dictionary
The dictionary should be inside an async function.
async def some_func():
data = await DB.to_dict(123, "col1_name", "col2_name", ...)
You can insert any number of columns, or you can get all by specifying the column name as '*'
data = await DB.to_dict(123, "*")
so you now have made some changes to your dictionary and want to export it to sql format again?
Convert dict to sqlite table
async def some_func():
...
await DB.to_sql(123, data)
But what if you want a list of values for a specific column?
Select method
you can have a list of all values of a certain column.
column1_values = await DB.select("col1_name")
to limit your selection use limit
parameter.
column1_values = await DB.select("col1_name", limit=10)
you can also arrange your list
by using ascending
parameter
and/or order_by
parameter and specifying a certain column to order your list accordingly.
column1_values = await DB.select("col1_name", order_by="col2_name", ascending=False)
delete method
delete a certain row from the table by defining the id of the row.
async def some_func():
...
await DB.delete(123)
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
Please notice that
this package is built-on top of aiosqlite
MIT
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 Distributions
Built Distribution
Hashes for aiosqlitedict-0.0.15-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd98af88389582bc0360b51a6e9b1e5e39501c63879ddea384515bc47aef4934 |
|
MD5 | e9cb340cf226bb9827845fc64af19522 |
|
BLAKE2b-256 | 97feb2e143ee53e610b22a14dd523581513e2361d3ebeb987127de348e1c36c6 |