Skip to main content

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)

Release files for ansqlite 0.4.2

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

Source distribution (sdist)

Source distribution for ansqlite 0.4.2
File Size Uploaded
ansqlite-0.4.2.tar.gz 4.5 kB Details

Built distribution (wheel)

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

Total release size: 9.9 kB

Release files / ansqlite-0.4.2.tar.gz

Download URL ansqlite-0.4.2.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
75751074b6e80de73f2aaffe0961883c064a3edea2cf050bda55c2fa4aacc7d4
BLAKE2b-256 checksum
How to use checksums
a633c549eb32eccaeaa31719a77d5958c980cbc0ac4b267ac798953498d2b351
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.9

Release files / ansqlite-0.4.2-py3-none-any.whl

Download URL ansqlite-0.4.2-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
68384902aebb03c8fde561c81aab9b125447bc93e3ffd7fa1b669f7cc2159583
BLAKE2b-256 checksum
How to use checksums
be872fbba3e21522066ad459a1c05dfb26ea0919a202d9ad49c34100aafad250
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.9

Release history Release notifications | RSS feed

This release

0.4.2 This release

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

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