Skip to main content

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


Release history Release notifications

History Node

0.99.4

History Node

0.99.2

History Node

0.99.1

History Node

0.99.0

This version
History Node

0.98

Supported by

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