Skip to main content

Conversion between a sqlite3 table and a python dictionary.

Project description

aiosqlitedictbanner

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

aiosqlitedict-0.0.15-py3-none-any.whl (5.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page