Skip to main content

A thread safe queue worker that executes SQL for multi-threaded applications.

Project description

Sqlite3 Execution Queue

version license pyversions
donate powered made

A thread safe queue worker that executes SQL for multi-threaded applications.

Hierarchy

sqlqueue
'---- SqlQueue()
    |---- sql()
    |---- _sql()
    |---- commit()
    '---- stop()

Example

python

from sqlq import *

# specify the db file, relative or absolute path
sqlqueue = SqlQueue(r"db.db")


# run benchmark
# this example shows how sqlq is used
# SQL should not be executed frequently
# see next example for sqlq usage
r = (1, 5, 10, 50, 100, 200)
r = (50,)
for l in r:
    tw = ThreadWrapper(threading.Semaphore(l))
    starttime = time.time()
    for i in range(l):
        def job(i):
            sqlqueue._sql(threading.get_ident(), "INSERT INTO test VALUES (?);", (str(i),))
        tw.add(job, args=args(i))
    tw.wait()
    p(l, (time.time()-starttime)/l, time.time()-starttime)
    # p(sql.sql("SELECT * FROM test;"))
    tw = ThreadWrapper(threading.Semaphore(l))
    starttime = time.time()
    for i in range(l):
        def job(i):
            sqlqueue._sql(threading.get_ident(), f"DELETE FROM test WHERE a = ?;", (str(i),))
        tw.add(job, args=args(i))
    tw.wait()
    p(l, (time.time()-starttime)/l, time.time()-starttime)


    starttime = time.time()
    for i in range(l):
        sqlqueue.sql("INSERT INTO test VALUES (?);", (str(i),))
    p(l, (time.time()-starttime)/l, time.time()-starttime)
    # p(sql.sql("SELECT * FROM test;"))
    starttime = time.time()
    for i in range(l):
        sqlqueue.sql(f"DELETE FROM test WHERE a = ?;", (str(i),))
    p(l, (time.time()-starttime)/l, time.time()-starttime)
    p()
    sqlqueue.commit()


# SQL execution modes
SqlQueue().sql("SELECT * FROM table;")
SqlQueue().sql("INSERT INTO table VALUES (?);", (0,))
SqlQueue().sql("INSERT INTO table VALUES (?);", ((0,),(0,)))
SqlQueue().sql('''
CREATE TABLE "tablea" ("a" TEXT);
DELETE TABLE "table";
''')

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

sqlq-0.0.3.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

sqlq-0.0.3-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file sqlq-0.0.3.tar.gz.

File metadata

  • Download URL: sqlq-0.0.3.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.0

File hashes

Hashes for sqlq-0.0.3.tar.gz
Algorithm Hash digest
SHA256 8674d693db637560238de06fb219cbfa0b9e480baf1cd4507c55b9458a00ae29
MD5 c02a5f2826699517072a261e9d22acaa
BLAKE2b-256 1d9c0c32e7653ec9b0c7247e7cc27f51c5506fc47224ba36620f3046ece661c9

See more details on using hashes here.

File details

Details for the file sqlq-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: sqlq-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.0

File hashes

Hashes for sqlq-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1d868f9542b1cba282d7c42b4e21a6602c0e682b41df94dba32209c07a54a960
MD5 23762704a2ca34975bc541c18b78f626
BLAKE2b-256 72ea5f021b3047f3a398766c01b9e9aee75d2012106491b235e10f72826f3867

See more details on using hashes here.

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