This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

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 now();

becomes an object with a single attribute t:

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

A QuerySelector object is iterable, providing pairs of name and query in the order that the queries originally appeared in the file.

>>> for name, q in qs:
...     print '%s: %s' % (name, q)
t: Query(args=[], mode=u'one', readonly=True, text='SELECT now();')

The Query Convention

If you have a script task.py and a SQL file task.sql, or a module in a package package/module.py and a SQL file package/module.sql, QuerySelector has a shortcut for you:

from query_selector.magic import queries


for q in queries:
    print q

The magic module overrides the normal module loading machinery to determine which script or module is importing it and locate an adjacent SQL file. This magic is in a separate module to make it stricly opt-in!

Modes

Modes can be one of none, one, one? and many. When not specified, default is many. A mode string can also be followed with the single word ro as a clue that the query is read-only.

Realistically, SELECT now() is a read-only query. We can annotate it as such, the resulting query datastructure records this:

>>> QuerySelector("""
...   --@ t one ro
...   SELECT now();
... """).t
Query(args=[], mode=u'one', readonly=True, text=u'SELECT * FROM now();')

Parameters

query-selector recognizes the %(...)s style parameter references defined in Python DBI 2.0. Say that we’d like to pass a timezone when selecting the server time. We can do so by adding AT TIME ZONE %(tz)s to our query. The presence of this parameter is stored in the args field of the parsed result. (The parameters in .args are listed in the order of their first appearance in the query.)

>>> QuerySelector("""
...     --@ t one ro
...     SELECT now() AT TIME ZONE %(tz)s AS t;
... """).t
Query(args=[u'tz'], mode=u'one', readonly=True,
      text=u'SELECT now() AT TIME ZONE %(tz)s AS t;')
Release History

Release History

0.99.4

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.99.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.99.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.99.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.98

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
query-selector-0.99.4.tar.gz (5.3 kB) Copy SHA256 Checksum SHA256 Source May 19, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting