Skip to main content

Generate SQL programmatically with function calls

Project description


Generate SQL with functional calls.

Use base set of tokens:

from sqlang import SQL, tokens

S = SQL(tokens)

expr = S.SELECT([S.FIELD('id')], S.FROM(S.TABLE('example')))

 "SELECT id FROM example;"

Add your own expression tokens:

from sqlang.sql import SQL as SQL_
from sqlang.sql import token_list, token_list_item, tokens

t2 = token_list(
    token_list_item('REPLACE', lambda e, *args: f"REPLACE({e(args[0])}, {e(args[1])}, {e(args[2])})"),
    token_list_item('WHERE', lambda e, *args: f"WHERE {e(args[0])}"),
    token_list_item('NOT_LIKE', lambda e, *args: f"{e(args[0])} NOT LIKE {e(args[1])}"),

SQL = SQL_(t2)

Project details

Release history Release notifications | RSS feed

This version


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for sqlang, version 0.2
Filename, size File type Python version Upload date Hashes
Filename, size sqlang-0.2-py3-none-any.whl (9.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size sqlang-0.2.tar.gz (4.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page