A KnexJS like module for abstracting Python's SQLite
Project description
Knexpy
A query builder for SQLite3 based on Knexjs
Features
- Transactions
- Type Checking
- Bulk Insert
- JSON mapping
You can report bugs and discuss feature on the GitHub issues page. For more detailed information check Readthedocs
Examples
Creating a Table
from Knexpy import Knex, Field
db = Knex("<Database File Name/Path>")
db.table(
"c",
[
Field.integer("field"),
],
not_exists=False,
)
db.table(
"t",
[
Field.varchar("field"), # Default size: 255
Field.varchar("field2"),
Field.varchar("field3"),
Field.foreign_key("field4", "c", "id"),
],
not_exists=False, # IF NOT EXISTS clause. Defaults to True
)
When creating a table the fields
id
,created_at
,modified_at
are automatically generated. Theid
field is a hash based on the information of the Row
Basic Select
from Knexpy import Knex
db = Knex("<Database File Name/Path>")
query = (
db.select("id", "field", "field2", ["field3", "test"],...) # List type on select acts as an alias
.from_("t")
.where("field", "=", "12345")
.order_by("id")
)
query.query() # Returns data as JSON
query.query(False) # Returns data as tuples
Select with Subquery
from Knexpy import Knex
db = Knex("<Database File Name/Path>")
query = (
db.select("id", "field", "field2", ["field3", "test"],...)
.from_("t")
.where("field", "=", "12345")
.where(
"field4",
"=",
db.subquery().select("id").from_("c").where("field", "=", 12345),
join_type="OR", # If attribute not present defaults to "AND".
)
.order_by("id")
)
query.query() # Returns data as JSON
Insert JSON Data
from Knexpy import Knex
db = Knex("<Database File Name/Path>", type_check=True) # type_check enables type checking (duh) when inserting/updating data
db.insert_json("<table>", {
"field": "1",
"field2": "2",
"field3": "3"
})
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
knexpy-0.1.3.tar.gz
(638.8 kB
view details)
File details
Details for the file knexpy-0.1.3.tar.gz
.
File metadata
- Download URL: knexpy-0.1.3.tar.gz
- Upload date:
- Size: 638.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 195c42a56d9f555e3d3dbf86b4229f57956fb04ee378cc2493f7dc3edc011e55 |
|
MD5 | f5ec09e225449bc4ea2d120091b513c2 |
|
BLAKE2b-256 | 90753ab11d164c1ef9673ad26b425c167297e2296544d28fef926f80a8896a19 |