{ "info": { "author": "Jason Dusek", "author_email": "jason.dusek@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: POSIX", "Operating System :: Unix", "Programming Language :: Python", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.5", "Topic :: Software Development" ], "description": "==================\n``query-selector``\n==================\n\n.. image:: https://travis-ci.org/solidsnack/query-selector.svg?branch=master\n :target: https://travis-ci.org/solidsnack/query-selector\n\nQuery selector allows one treat a file full of SQL queries as a record, with\none attribute for each annotated query. This makes working with long, ad-hoc\nSQL queries more hygienic, and has the benefit of making it easy to find the\nqueries.\n\nThe ``QuerySelector`` constructor accepts a string, file handle or\n``(, ``. The ```` is any Python compatible name; it will\nbecome an attribute of the object. The ```` is merely metadata, and can\nbe omitted; it describes whether a query should have one, none or many\nresults.\n\nFor example, a file like this:\n\n.. code:: sql\n\n --@ t one\n SELECT now();\n\nbecomes an object with a single attribute ``t``:\n\n.. code:: pycon\n\n >>> q.t\n Query(args=[], mode=u'one', readonly=False, text=u'SELECT * FROM now();')\n\nA ``QuerySelector`` object is iterable, providing pairs of name and query in\nthe order that the queries originally appeared in the file.\n\n.. code:: pycon\n\n >>> for name, q in qs:\n ... print '%s: %s' % (name, q)\n t: Query(args=[], mode=u'one', readonly=True, text='SELECT now();')\n\n--------------------\nThe Query Convention\n--------------------\n\nIf you have a script `task.py` and a SQL file `task.sql`, or a module in a\npackage `package/module.py` and a SQL file `package/module.sql`, QuerySelector\nhas a shortcut for you:\n\n.. code:: python\n\n from query_selector.magic import queries\n\n\n for q in queries:\n print q\n\nThe ``magic`` module overrides the normal module loading machinery to\ndetermine which script or module is importing it and locate an adjacent SQL\nfile. This magic is in a separate module to make it stricly opt-in!\n\n-----\nModes\n-----\n\nModes can be one of ``none``, ``one``, ``one?`` and ``many``. When not\nspecified, default is ``many``. A mode string can also be followed with the\nsingle word ``ro`` as a clue that the query is read-only.\n\nRealistically, ``SELECT now()`` is a read-only query. We can annotate it as\nsuch, the resulting query datastructure records this:\n\n.. code:: pycon\n\n >>> QuerySelector(\"\"\"\n ... --@ t one ro\n ... SELECT now();\n ... \"\"\").t\n Query(args=[], mode=u'one', readonly=True, text=u'SELECT * FROM now();')\n\n----------\nParameters\n----------\n\n``query-selector`` recognizes the ``%(...)s`` style parameter references\ndefined in Python DBI 2.0. Say that we'd like to pass a timezone\nwhen selecting the server time. We can do so by adding ``AT TIME ZONE %(tz)s``\nto our query. The presence of this parameter is stored in the ``args`` field\nof the parsed result. (The parameters in ``.args`` are listed in the order of\ntheir first appearance in the query.)\n\n.. code:: pycon\n\n >>> QuerySelector(\"\"\"\n ... --@ t one ro\n ... SELECT now() AT TIME ZONE %(tz)s AS t;\n ... \"\"\").t\n Query(args=[u'tz'], mode=u'one', readonly=True,\n text=u'SELECT now() AT TIME ZONE %(tz)s AS t;')\n", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/solidsnack/query-selector", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "query-selector", "package_url": "https://pypi.org/project/query-selector/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/query-selector/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/solidsnack/query-selector" }, "release_url": "https://pypi.org/project/query-selector/0.99.4/", "requires_dist": null, "requires_python": null, "summary": "Organize app queries in an annotated SQL file.", "version": "0.99.4" }, "last_serial": 2123125, "releases": { "0.98": [], "0.99.0": [ { "comment_text": "", "digests": { "md5": "709ed939270b9608ea4a206b1d317383", "sha256": "11a3b1ee9ba3a2c0eccc8f647e4ea162ead73c43f420e267b894acda4d16d74c" }, "downloads": -1, "filename": "query-selector-0.99.0.tar.gz", "has_sig": false, "md5_digest": "709ed939270b9608ea4a206b1d317383", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3818, "upload_time": "2016-04-15T07:04:41", "url": "https://files.pythonhosted.org/packages/8a/90/347a7f836579b02e44347a17df793cbf60a97340f1bc6b5a33aa5615a699/query-selector-0.99.0.tar.gz" } ], "0.99.1": [ { "comment_text": "", "digests": { "md5": "04131e61c77cd291578063f79a358d18", "sha256": "cca45f2b8e2359804ba6de1ebc4055e431e0487b4d8165306c877d2728dd5a36" }, "downloads": -1, "filename": "query-selector-0.99.1.tar.gz", "has_sig": false, "md5_digest": "04131e61c77cd291578063f79a358d18", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4350, "upload_time": "2016-04-16T23:04:48", "url": "https://files.pythonhosted.org/packages/4a/27/95e76908d4574233e381a039faeeae76e912ffa11cf61caba346fbd9c57d/query-selector-0.99.1.tar.gz" } ], "0.99.2": [ { "comment_text": "", "digests": { "md5": "5980aa5b8e13bba3774903df19b0e2a2", "sha256": "6255fc2470c7ce4a243ade5a672af42b1309ab3d266922762ce468b93a25bd16" }, "downloads": -1, "filename": "query-selector-0.99.2.tar.gz", "has_sig": false, "md5_digest": "5980aa5b8e13bba3774903df19b0e2a2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4580, "upload_time": "2016-04-17T22:21:10", "url": "https://files.pythonhosted.org/packages/3f/17/d553380a9d428da3dea8d4c06877711c2b98cd4c333d094bd779f21ff40d/query-selector-0.99.2.tar.gz" } ], "0.99.4": [ { "comment_text": "", "digests": { "md5": "bfd043048b6d27cd441015fbed5aa04a", "sha256": "a71cb745d1452cffd1910a80c319f15fc34db6eae4b5e50ca8134460bd2b189c" }, "downloads": -1, "filename": "query-selector-0.99.4.tar.gz", "has_sig": false, "md5_digest": "bfd043048b6d27cd441015fbed5aa04a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5273, "upload_time": "2016-05-19T06:55:48", "url": "https://files.pythonhosted.org/packages/d5/74/ea01e308c61aa1e67ecf2fbfbca5c6c063b683f5e40477bbc06033bf3087/query-selector-0.99.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "bfd043048b6d27cd441015fbed5aa04a", "sha256": "a71cb745d1452cffd1910a80c319f15fc34db6eae4b5e50ca8134460bd2b189c" }, "downloads": -1, "filename": "query-selector-0.99.4.tar.gz", "has_sig": false, "md5_digest": "bfd043048b6d27cd441015fbed5aa04a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5273, "upload_time": "2016-05-19T06:55:48", "url": "https://files.pythonhosted.org/packages/d5/74/ea01e308c61aa1e67ecf2fbfbca5c6c063b683f5e40477bbc06033bf3087/query-selector-0.99.4.tar.gz" } ] }