Skip to main content
Join the official Python Developers Survey 2018 and win valuable prizes: Start the survey!

Organize app queries in an annotated SQL file.

Project description

https://travis-ci.org/solidsnack/query-selector.svg?branch=master

Query selector allows one treat a file full of SQL queries as a record, with one attribute for each annotated query. This makes working with long, ad-hoc SQL queries more hygienic, and has the benefit of making it easy to find the queries.

The QuerySelector constructor accepts a string, file handle or (<package>, <resource) pair and parses the SQL into groups annotated with --@ <name> <mode>. The <name> is any Python compatible name; it will become an attribute of the object. The <mode> is merely metadata, and can be omitted; it describes whether a query should have one, none or many results.

For example, a file like this:

--@ t one
SELECT * FROM now();

becomes and object with a single attribute t:

>>> q.t
Query(args=[], mode=u'one', text=u'SELECT * FROM now();')

Project details


Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page