Skip to main content

SqliteDao

PyPI version   Python 3.x   PyPI license   Downloads   Unit Test

A simplified DAO for SQL abstraction for personal projects.

pip install sqlitedao

Demo project: sqlite_img_app

Examples

Create Table easily:

from sqlitedao import SqliteDao

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:

from sqlitedao import ColumnDict

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": ["position"]
}
dao.create_table(TEST_TABLE_NAME, columns, create_table_indexes)

Retrieve items as a list of python dictionaries:

from sqlitedao import SearchDict

search = SearchDict().add_filter("age", 50, operator=">")
rows = xdao.search_table(TEST_TABLE_NAME, search)
# [{"name": "Michael Jordan", "position": "SG", "age": 56, "height": "6-6"}]

Create DAO classes by inheriting TableItem easily and deal with less code:

from sqlitedao import TableItem, SearchDict

class Player(TableItem):

    TABLE_NAME = TEST_TABLE_NAME
    INDEX_KEYS = ["name"]
    ALL_COLUMNS = {
        "name": str,
        "position": str,
        "age": int,
        "height": str
    }

    def __init__(self, row_tuple=None, **kwargs):
        super().__init__(row_tuple, **kwargs)
        self.load_tuple()

    def load_tuple(self):
        self.name = self.row_tuple["name"]
        self.position = self.row_tuple["position"]
        self.age = self.row_tuple["age"]
        self.height = self.row_tuple["height"]

    def grow(self):
        self.age += 1
        self.row_tuple['age'] += 1


# Perform DAO action with above structured class
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)

# Pagination with sqlite is easier than ever!
old = SearchDict().add_filter("age", 35, ">")
old_team_1 = dao.get_items_page(Player, old, None, limit = 10)
old_team_2 = dao.get_items_page(Player, old, old_team_1[-1], limit = 10)

see test files for more examples. This can greatly simplify and ease the creation cost for pet projects based on sqlite.

Metadata

Release files for sqlitedao 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlitedao 0.8.0
File Size Uploaded Provenance Actions
sqlitedao-0.8.0.tar.gz 7.6 kB Without provenance Details for sqlitedao-0.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sqlitedao 0.8.0
File Interpreter ABI Platform Actions
sqlitedao-0.8.0-py3-none-any.whl Python 3 none any Details for sqlitedao-0.8.0-py3-none-any.whl

Total release size: 14.7 kB

Release files / sqlitedao-0.8.0.tar.gz

Download URL sqlitedao-0.8.0.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
09986463f9516274b23507a31894d8cdd779f6bc5b848b0a9fb423ed3a4917ba
BLAKE2b-256 checksum
How to use checksums
03ba80c3b241bf92290a286561f4a9c62e0b0fbc33e8412779515f88a2469f79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / sqlitedao-0.8.0-py3-none-any.whl

Download URL sqlitedao-0.8.0-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c3527d60375a9fca9779c6c817f728b2f425862bd0541583f5a6a703d45b5a5a
BLAKE2b-256 checksum
How to use checksums
444213975954d5ebdf3126873c205110eec45064f69fd50bfbe9a260afea99ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Security for sqlitedao 0.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page