{ "info": { "author": "merry-bits", "author_email": "merry-bits@users.noreply.github.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License v2 (GPLv2)", "Natural Language :: English", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Topic :: Database :: Front-Ends" ], "description": "DBQuery: make database queries easy\n===================================\n\n.. image:: https://api.travis-ci.org/merry-bits/DBQuery.svg?branch=master\n :target: https://travis-ci.org/merry-bits/DBQuery?branch=master\n\nA comfortable database configuration and query wrapper for the Python DB-API.\n\n\nExample\n-------\n\nSample code for connecting to an existing SQLite database and\nprinting some rows from a table named world:\n\n.. code-block:: python\n\n >>> import dbquery\n >>> db = dbquery.SQLiteDB('test.db')\n >>> get_hello = db.Select('SELECT hello FROM world WHERE id=?')\n >>> for hello_id in (123, 456):\n ... rows = get_hello(hello_id)\n ... print(rows) # list of row tuples\n ...\n [('hello',)]\n [('another hello',)]\n\nUsing ``SelectOne`` instead of ``Select`` this can be simplified even further:\n\n.. code-block:: python\n\n >>> get_one_hello = db.SelectOne('SELECT hello FROM world WHERE id=?')\n >>> for hello_id in (123, 456):\n ... hello = get_one_hello(hello_id)\n ... print(hello) # content of the hello column\n ...\n hello\n another hello\n\n\nSet up a database for the example code\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: bash\n\n $ sqlite3 test.db\n sqlite> CREATE TABLE world (id INTEGER, hello VARCHAR);\n sqlite> INSERT INTO world VALUES (123, 'hello'), (456, 'another hello');\n\nWith this you can use ``test.db`` as database in the above examples. Just be\nsure you call python from the same directory as where the database file is.\n\n\nSupported databases\n-------------------\n\n* SQLite\n* PostgreSQL (requires the presence of\n `Psycopg2 `_)\n\n\nInstallation\n============\n\n.. code-block:: bash\n\n $ pip install dbquery\n\n\nDocumentation\n=============\n\nThe `Python DB-API `_ specifies\nconnections and cursors for executing SQL. DBQuery is designed to hide this\ncomplexity when it is not needed. Instead it provides a DB and a Query class\nfor executing SQL. ``DB`` (or one of its sub classes like ``SQLiteDB``) saves\nthe connection information and provides access to the ``Query`` classes which\nuse this to execute the provided SQL.\n\nThis way a it is possible work with SQL queries as if they where functions:\n\n.. code-block:: python\n\n >>> db = dbquery.db.DB()\n >>> get_user = db.SelectOne(\n ... \"Select email, first_name FROM users WHERE user_id=?\")\n >>> email, first_name = get_user(123)\n\nWhat is more, if the connection to a database gets lost DBQuery can\nautomatically try to reconnect up to a specified count of retries:\n\n.. code-block:: python\n\n >>> db = dbquery.db.DB(configuration, retry=3) # retry to connect 3 times\n\n\nConfiguration\n-------------\n\nThe exact behavior depends on the actual DB implementation for a specific\ndatabase. In general all configuration parameters are passed to the DB\nconstructor. Usually a connection to the database will not be opened until the\nfirst query is made\n\n\nSQLiteDB\n^^^^^^^^\n\n``database, **kwds`` parameters of the SQLiteDB constructor will be passed on\nthe the SQLite connect function.\n\n\nPostgreSQL\n^^^^^^^^^^\n\nAccepts either the DSN string or configuration parameters for the Psqycopg2\nconnect function as keyword parameters.\n\n\nTransaction\n-----------\n\nThe DB instance acts as a context manager for starting a connection on\nentering the context and committing the queries in between in exit. If an\nexception happens a ``rollback`` call will be made instead.\n\n**Note**: ``SQLiteDB`` does not implement this feature.\n\n\nQuery\n-----\n\nExecutes a SQL query without being interested in any result. It is the base\nclass for all other queries.\n\nOverwrite ``_produce_return`` if you are interested in creating your own class\nthat does something with the cursor that executed the query.\n\n\nQueryCursor\n^^^^^^^^^^^\n\nExecutes the given SQL then returns the curser for direct access. Use within\na context. Exiting the context will close the cursor.\n\nFor example perform a `fetchone`:\n\n.. code-block:: python\n\n >>> get_first_name_cursor = db.QueryCursor(\n ... \"SELECT first_name FROM users where id=?\")\n >>> with get_first_name_cursor(123) as cursor:\n ... print(cursor.fetchone())\n ...\n ('Foo',)\n >>>\n\n\nManipulation\n^^^^^^^^^^^^\n\nUse this to execute any ``INSERT``, ``UPDATE`` and similar queries when the\n``rowcount`` of the cursor should be returned. It is possible to automatically\ncheck the value of the row count by setting the ``rowcount`` parameter. If the\nresulting row count does not match the provided one a ManipulationCheckError\nwill be raised.\n\nThis can be used to for example make sure that only one row was updated by a\nquery:\n\n.. code-block:: python\n\n >>> update_user_name = db.Manipulation(\n ... \"UPDATE users SET first_name=? WHERE id=?\", rowcount=1)\n >>> with db: # start a new transaction, does not work with SQLiteDB!\n ... update_user_name(\"new_name\", 123) # roll back if rowcount != 1\n ...\n 1\n >>>\n\n\nSelect\n^^^^^^\n\nReturns the result of ``fetchall()``, making it ideal for SELECT queries.\n\n\nSelectOne\n^^^^^^^^^\n\nChecks that only one row is returned by the specified query. Returns ``None``\notherwise. If the result row contains only one column then only that columns\nvalue will be returned:\n\n.. code-block:: python\n\n >>> get_first_name = db.SelectOne(\n ... \"SELECT first_name FROM users where id=?\")\n >>> get_first_name(123)\n 'Foo'\n >>>\n\n\nSelectIterator\n^^^^^^^^^^^^^^\n\nSelect rows and precess them in chunks. For this purpose ``SelectIterator``\nrequeires a callback function together with the SQL. This callback will at\nquery time be called with a generator which produces all the rows from the\nquery result, directly streamed from the DB, in blocks of specified size\n(``arraysize``).\n\nIt is possible to specify additional parameters for the callback function, if\nneeded.\n\n.. code-block:: python\n\n >>> def callback(row_generator):\n ... for row in row_generator:\n ... print(row)\n ...\n >>> get_first_names = db.SelectIterator(\n ... \"SELECT first_name FROM users\", callback)\n >>> get_first_names()\n ('Foo',)\n >>>\n\n\nChangelog\n=========\n\n\nv0.4.1\n------\n\n* Added `SelectIterator` iteration `QueryCursor` which allows direct cursor\n access\n\n\nv0.4.0\n------\n\n* Added `SelectIterator`", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/merry-bits/DBQuery", "keywords": "easy database access SQLite PostgreSQL wrap SQL connection query", "license": "GPLv2", "maintainer": "", "maintainer_email": "", "name": "DBQuery", "package_url": "https://pypi.org/project/DBQuery/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/DBQuery/", "project_urls": { "Homepage": "https://github.com/merry-bits/DBQuery" }, "release_url": "https://pypi.org/project/DBQuery/0.4.1/", "requires_dist": [ "psycopg2 (>=2.6.2); extra == 'postgres'" ], "requires_python": "", "summary": "Simplify your database access.", "version": "0.4.1" }, "last_serial": 2352998, "releases": { "0.3.0": [ { "comment_text": "", "digests": { "md5": "99f35b7145342c7782ec7ea47c699495", "sha256": "a6afadca4ee2eabb341f992fb3d33ad64568bbc839906bbe58bb434f3db8df08" }, "downloads": -1, "filename": "DBQuery-0.3.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "99f35b7145342c7782ec7ea47c699495", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 13043, "upload_time": "2015-11-25T06:50:56", "url": "https://files.pythonhosted.org/packages/b5/db/b45c639494ffbd68f53c10ee9dd66dd19c8c05ae5679f027d1a64da5babf/DBQuery-0.3.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ea05359df6e50071b5aa3503ce71ebd7", "sha256": "eeadff8e7cfb90e267e7f0b77142e1bac74aa0a3af619fc1fa6f48dc8c850bf2" }, "downloads": -1, "filename": "DBQuery-0.3.0.tar.gz", "has_sig": true, "md5_digest": "ea05359df6e50071b5aa3503ce71ebd7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8663, "upload_time": "2015-11-25T06:51:01", "url": "https://files.pythonhosted.org/packages/89/60/739c57be2dee7f6de23c7af3a7dfe06a86fe32a082877bbd5e25264bcec5/DBQuery-0.3.0.tar.gz" } ], "0.3.0.dev2": [ { "comment_text": "", "digests": { "md5": "fa154441d856564d295191eb9e8c06d9", "sha256": "ea8ae8585b15e88610fc52d5246c4b33c32c3a9377ae8fc8441bc9a5c77a2ced" }, "downloads": -1, "filename": "DBQuery-0.3.0.dev2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "fa154441d856564d295191eb9e8c06d9", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 12899, "upload_time": "2015-11-11T23:20:49", "url": "https://files.pythonhosted.org/packages/18/1f/0d171aef65e7e6d950d99fea5f050dff19c9b348674fcb2f6c6f6768ed1c/DBQuery-0.3.0.dev2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "219f6ee1c77094ec61014cc46215aa30", "sha256": "bbff27932dfca4a36e64c8aa3f58860e6d6c14fa5e054ea3701a0b57fa5973f0" }, "downloads": -1, "filename": "DBQuery-0.3.0.dev2.tar.gz", "has_sig": true, "md5_digest": "219f6ee1c77094ec61014cc46215aa30", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8479, "upload_time": "2015-11-11T23:20:57", "url": "https://files.pythonhosted.org/packages/04/d4/6443733ce2de8e27c0db2916cfadfa10bca9f5c04d4a734c7c63e7a21772/DBQuery-0.3.0.dev2.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "66f5689f7a841a28f1ae14acf5da40ea", "sha256": "fa1d9e9e5abeac7c3bd1eb296a66b814fad6b81c8560180917342c612086194d" }, "downloads": -1, "filename": "DBQuery-0.3.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "66f5689f7a841a28f1ae14acf5da40ea", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 13444, "upload_time": "2016-01-04T22:35:04", "url": "https://files.pythonhosted.org/packages/6c/94/938c29c72d5bf4bb6002b1c1440edde739258f6cae15839abd88b5195977/DBQuery-0.3.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "538c84ebf71d311a65ab60c598fabc91", "sha256": "05f3f1a089f578f560dbea4080d6908c1b0bcc97b57f5177cca4d27f5453fa78" }, "downloads": -1, "filename": "DBQuery-0.3.1.tar.gz", "has_sig": true, "md5_digest": "538c84ebf71d311a65ab60c598fabc91", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8946, "upload_time": "2016-01-04T22:35:33", "url": "https://files.pythonhosted.org/packages/2f/89/9dc9bd1f469e8a0fc2e1d97d7d47b64328190173c333aa4db923aff2607e/DBQuery-0.3.1.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "5804d6804231ae14db28f5ee0b42bc75", "sha256": "d7b077c577a1f58085a0949d57df679221487c2f71f42e14c4078e8dd33805d6" }, "downloads": -1, "filename": "DBQuery-0.4.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "5804d6804231ae14db28f5ee0b42bc75", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 14569, "upload_time": "2016-09-19T06:49:03", "url": "https://files.pythonhosted.org/packages/c1/ea/8a77c1a2580dd25fe5f3b746ff47aed0b07700239d5b07987b4132d2a511/DBQuery-0.4.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1d508849aa6c96b9343bd3f7f13d6b12", "sha256": "523e121b46fb75bb475054019a4013bcf90c499c2fba7ca96df6e07239aca2b5" }, "downloads": -1, "filename": "DBQuery-0.4.0.tar.gz", "has_sig": false, "md5_digest": "1d508849aa6c96b9343bd3f7f13d6b12", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12159, "upload_time": "2016-09-19T06:49:05", "url": "https://files.pythonhosted.org/packages/e8/5c/cd1e66145e07ca21384e57147fb411608f0c790e939be97d5c349cb7c7c3/DBQuery-0.4.0.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "ecfca4a3c878fc82b543f7bd19b47344", "sha256": "6aa353b8f846b3708f406ab2223c49b5cf79fd53434e16e2330e2164a5a034d0" }, "downloads": -1, "filename": "DBQuery-0.4.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "ecfca4a3c878fc82b543f7bd19b47344", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 15443, "upload_time": "2016-09-20T13:42:40", "url": "https://files.pythonhosted.org/packages/8c/34/80cc35bd49a09230d299a8fc1d7cdabe5b837fad62601106d109753f1b46/DBQuery-0.4.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "073a4106114d339bba063cac03c6bddb", "sha256": "b591d5afed4095490c859b928ec07a92adfcea5d09715350d64581d4e728adfb" }, "downloads": -1, "filename": "DBQuery-0.4.1.tar.gz", "has_sig": false, "md5_digest": "073a4106114d339bba063cac03c6bddb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12956, "upload_time": "2016-09-20T13:42:43", "url": "https://files.pythonhosted.org/packages/e2/1c/13b62f3db0e7a89ead12f7efe2e1df85e56092d2fa74e529d37487eb7d11/DBQuery-0.4.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ecfca4a3c878fc82b543f7bd19b47344", "sha256": "6aa353b8f846b3708f406ab2223c49b5cf79fd53434e16e2330e2164a5a034d0" }, "downloads": -1, "filename": "DBQuery-0.4.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "ecfca4a3c878fc82b543f7bd19b47344", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 15443, "upload_time": "2016-09-20T13:42:40", "url": "https://files.pythonhosted.org/packages/8c/34/80cc35bd49a09230d299a8fc1d7cdabe5b837fad62601106d109753f1b46/DBQuery-0.4.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "073a4106114d339bba063cac03c6bddb", "sha256": "b591d5afed4095490c859b928ec07a92adfcea5d09715350d64581d4e728adfb" }, "downloads": -1, "filename": "DBQuery-0.4.1.tar.gz", "has_sig": false, "md5_digest": "073a4106114d339bba063cac03c6bddb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12956, "upload_time": "2016-09-20T13:42:43", "url": "https://files.pythonhosted.org/packages/e2/1c/13b62f3db0e7a89ead12f7efe2e1df85e56092d2fa74e529d37487eb7d11/DBQuery-0.4.1.tar.gz" } ] }