Skip to main content

A python object-oriented wrapper for sqlite

Project description

sqlitewrapper

A python object-oriented wrapper for sqlite, based on sqlite3

Key features

sqlitewrapper covers a wide range of queries, with a few additional features

  • Easily create and run queries
  • Easily intergrate queries into programs
  • Database and table methods
  • Thread safe

Installation

pip install sqlitewrapper

Examples

Creating a table

import sqlitewrapper
from sqlitewrapper import types

columns = {
    "id": types.primary(autoincrement=True),
    "token": types.unique(str),
    "username": types.notnull(str),
    "tag": types.default(0),
    "desc": types.blob, # types.null(types.blob) also works
    #"joined": types.primary # types.primary() and types.primary(int) also work, but you can't have multiple primary keys if one of them is autoincrementing
}

db = sqlitewrapper.database("my_database")
table = db.create("my_table", columns)

Adding and removing columns

db = sqlitewrapper.database("my_database")
table = db.table("my_table")

table.removeColumn("desc")
table.addColumn(bio=blob)

Adding and removing rows

table.add(token="arZrJFbECw", username="user1") # id will be 1, and tag will be 0
table.add(token="xpReueejDK", username="user2") # id will be 2, and tag will be 0
table.add(token="JwVSFbpRnI", username="user3")

# can use logical queries so must be run
table.remove().where("id").eq(2).run()

Getting data from the table

# gets all the values in the first row where the token equals 'arZrJFbECw'
result = table.get().where("token").eq("arZrJFbECw").run()

# gets all the usernames in every row
result = table.getAll("username").run()

Updating data in the table

# sets desc to null where tokens equals 'arZrJFbECw'
table.set(desc=types.null).where("token").eq("arZrJFbECw").run()

# increase tag by 1000 if tag is equal to 0 or 1
table.set(tag=types.increment(1000)).IN(0, 1).run()

Don't await completion

This is to allow sqlitewrapper to run write queries without the main program having to wait for it's completion

NOTE: The query execution rotates attempting to execute a read query and then a write query, this is so the queue is not stacked up preventing one type of query from being executed

NOTE: When doing cleanup you can use db.waitForQueue(), which will run until the queue is empty

db = sqlitewrapper.database("my_database", await_completion=True)
table = db.table("my_table")

table.add(token="xrDIltpbBQ", username="user4")
result = table.getAll("username").run() # in most cases 'user4' won't show up

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

sqlitewrapper-0.1.1.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

sqlitewrapper-0.1.1-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file sqlitewrapper-0.1.1.tar.gz.

File metadata

  • Download URL: sqlitewrapper-0.1.1.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.10

File hashes

Hashes for sqlitewrapper-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2d8f31018dfe585e7fd5dc12a161ed66ee90203949f5cc4532eb5fb8e001e37c
MD5 d2d04c80bd3a98ddcd749690e0abd097
BLAKE2b-256 9f1c20fc39353b5ac1d06bce22c20fe3aab92368f4df810b15d39e29ea4798a2

See more details on using hashes here.

File details

Details for the file sqlitewrapper-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: sqlitewrapper-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.10

File hashes

Hashes for sqlitewrapper-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a4a52259538a56f3acb654d7a56e2a16f3b33418c672b13b5a9c069272b1b9fe
MD5 da43e4d796f19d911e375bfebf13bf4a
BLAKE2b-256 a3b66a7a427fc05ac79eb1420bfba3fc2c26e5dc4524810b13879afe5fdd08c5

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