Skip to main content

sql-smith is an SQL query builder with zero dependencies and a fluent interface.

Project description

sql-smith is an SQL query builder with zero dependencies and a fluent interface.

The sentence above is, beside the name, a copy from the website of the PHP library Latitude, for the simple reason that this Python module is a port of Latitude.

Installation

$ pip install sql-smith

Quick Start

QueryFactory is a factory to create a SELECT, INSERT, UPDATE or DELETE query. Use the fluent interface of the queries to complete the query.

from sql_smith import QueryFactory
from sql_smith.engine import CommonEngine
from sql_smith.functions import field

factory = QueryFactory(CommonEngine())
query = factory \
    .select('id', 'username') \
    .from_('users') \
    .where(field('id').eq(5)) \
    .compile()

print(query.sql)  # SELECT "id", "username" FROM "users" WHERE "id" = ?
print(query.params)  # (5)

When the query is ready, compile it. The return value of compile is a Query class instance with two properties: sql and params. Use these properties to pass the query to a database.

import sqlite3

db = sqlite3.connect('test.db')
cur = db.cursor()

for row in cur.execute(query.sql, query.params):
    print(row)

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

sql-smith-1.0.0.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

sql_smith-1.0.0-py3-none-any.whl (28.8 kB view details)

Uploaded Python 3

File details

Details for the file sql-smith-1.0.0.tar.gz.

File metadata

  • Download URL: sql-smith-1.0.0.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for sql-smith-1.0.0.tar.gz
Algorithm Hash digest
SHA256 91c13702a2b75680bacc728b92ef08d181382d029355bfc7f2ed325033773bac
MD5 0ac788d2b50eda883172769322217d0c
BLAKE2b-256 bb7f46b1886acc75fc62c2e5d290619d5253762f9ac8b87c32800747b0e8efba

See more details on using hashes here.

Provenance

File details

Details for the file sql_smith-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: sql_smith-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 28.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for sql_smith-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e5a2ccadb3d5b990380a7054e56d1e1826b9bd89415fe486788befefb314c375
MD5 9c16f29c82649d27e2f09d0e2daea347
BLAKE2b-256 bf7fc7f0c5778974e6c8d50f394c743a52c3336c4f24426686af0b117b68b33d

See more details on using hashes here.

Provenance

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