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)

Acknowledgment

Big thanks to JetBrains to let me use PyCharm for free!

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.1.0.tar.gz (13.7 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.1.0-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

Details for the file sql_smith-1.1.0.tar.gz.

File metadata

  • Download URL: sql_smith-1.1.0.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.10.6 Linux/5.15.0-71-generic

File hashes

Hashes for sql_smith-1.1.0.tar.gz
Algorithm Hash digest
SHA256 7b20e994fccb663eab700585c85dc4de0a3a8c170e123852a3f920331527da6c
MD5 c4bb94f12a02c3600cc595ae2bfc4427
BLAKE2b-256 937d3569fb2e6d7b235b81fc304efb5a1f070edc63356a14ce46b8f8c2db04e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sql_smith-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 29.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.10.6 Linux/5.15.0-71-generic

File hashes

Hashes for sql_smith-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82748edc2bbed45139a18de6d8c318830afd28c90e3377ca84f809b270f2cc1c
MD5 566f1216e891f808d6f67e6ea1e13324
BLAKE2b-256 902f51482fd5240edddc02788199c5e52221c2764d748d2bf49a41d14293ebbd

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