Skip to main content

Write queries in SQL.

Project description

# SQL-query

SQL is a fantastic language — one of the most successful programming languages in the world. We should use it, not try to replace it with a bespoke DSL.

Yet there are a couple of things that are nice to have help with in constructing SQL queries:

  • dialect-aware safe value substitution: Every database interface has its own syntax for substituting values safely (not to allow SQL injection) — for example, $1 or ? or :varname. They also have different requirements for the format of the sql + values argument lists. I want to able to write my queries with the same value substituion syntax, regardless of which database interface I am using, and know that the SQL will be output correctly for my interface, and that the values will be passed to the database engine safely.

  • dynamic attributes: In many applications, I don’t know in advance which attributes I am going to select, insert, update, or filter by. I want to SELECT a given list of attributes, or filter WHERE a given key/value mapping, or UPDATE or INSERT particular attributes, without having to rewrite the SQL query.

  • block composition: Some SQL queries are very complex. I want to able to compose blocks of SQL into larger queries, so that I can manage this complexity effectively. (Most database query DSLs are unable to deal with complex queries, or they invent a hard-to-learn language for writing those queries. Learning SQL is a better use of our time, but having some assistance managing/manipulating the different blocks in a query would be very helpful.)

Behold SQL-query: [OUTDATED]

  • One class, SQL, with one field, query, and one method, .render, which takes one optional argument, dialect.

  • Dynamic value replacement, rendered in one of the supported dialects: postgresql ($1), sqlalchemy (:varname), embedded (:varname), mysql (%(varname)s), sqlite (?). Default style is :varname.

  • Dynamic attribute/value lists in SELECT, WHERE, INSERT, and UPDATE syntax via ??? [TBD]

  • Block composition via ??? [TBD]

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-query-0.2.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

sql_query-0.2.0-py2.py3-none-any.whl (9.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file sql-query-0.2.0.tar.gz.

File metadata

  • Download URL: sql-query-0.2.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for sql-query-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f52f281042fdc37f70a13167e9a710e5ba7994ae4f2186692738cc9a975b0c1c
MD5 f56630de6343fe64d00781121d70c000
BLAKE2b-256 7d34e9f0058a8b07908a2e147cf046d0356170f2a2a636e70523f8bae57832fd

See more details on using hashes here.

File details

Details for the file sql_query-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: sql_query-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for sql_query-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 58bfda58dd7013686913b89461bf7e06ba6525c63eb427f5a5d9e9a8416184e8
MD5 5b78440869982179430bae24e480fb45
BLAKE2b-256 7c49cfc8aa7da1bd447cddceed5104897653ffe94b92fbeaf3d4b15c5c69ae2c

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