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.

Source Distribution

sqlang-0.2.tar.gz (4.6 kB view hashes)

Uploaded source

Built Distribution

sqlang-0.2-py3-none-any.whl (9.1 kB view hashes)

Uploaded py3

Supported by

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