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.

Read the full documentation.

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.1.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sql_smith-1.0.1-py3-none-any.whl (28.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sql-smith-1.0.1.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for sql-smith-1.0.1.tar.gz
Algorithm Hash digest
SHA256 54f80c0f8db1cd4477acffd8c60e57bc782888fd22c9cbe8dcf9506ee628750c
MD5 ba1bfba43981d0dc80f4b168d24dff90
BLAKE2b-256 79707070ea3635bebc26b440da638f2bf28d85e6faaebcfc508c2c553113b9ba

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sql_smith-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 28.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for sql_smith-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cbf7880cbde1a56baf5a75d920c12992bdebc16614a9c9aabc8aee2258251422
MD5 e0c56e18124fdb4aaecdc436f782235e
BLAKE2b-256 c678e3eee946e6223d1c91dc95926cd54492471b37446f718565d48413d67c4f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page