{ "info": { "author": "Outernet Inc", "author_email": "apps@outernet.is", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.4", "Topic :: Utilities" ], "description": "=========\nsqlize-pg\n=========\n\nSqlize-pg is a SQL query builder for Python. It's main goals are:\n\n- speed: because fast is good\n- transparency: do not hide the true nature of SQL\n- mutability: we should be able to mutate the query\n\nThis library is primarily developed for use with Postgresql and no efforts have\nbeen invested into testing or using with other database backends.\n\nInstallation\n============\n\nSqlize-pg can be installed using ``pip`` or ``easy_install`` as usual::\n\n pip install sqlize-pg\n\n\nIntroduction (quick tutorial)\n=============================\n\nThis section will provide a brief introduction to sqlize-pg. The examples are all\ndoctested, so rest assured that they work as expected.\n\nThe basic concept is to instantiate an object representing some type of query,\noptionally manipulate attributes on it to fine-tune the clauses, and finally\nconvert the query into SQL string by coercing it into string.\n\nNote that the queries are meant to be used with placeholder values, and **no\nquoting is performed by sqlize-pg**. The generated SQL strings are intended to be\nused with ``psycopg2.extensions.cursor.execute()``, and similar methods.\n\nA basic select looks like this::\n\n >>> import sqlize_pg as sql\n >>> q = sql.Select('*', sets='foo')\n\nNote that we call tables 'sets' to avoid the clash with Python's ``from``\nkeyword.\n\nTo convert the query to SQL, we simply coerce it into a ``str``::\n\n >>> str(q)\n 'SELECT * FROM foo;'\n\nYou can select multiple things::\n\n >>> str(sql.Select(['foo', 'bar'], sets='foo'))\n 'SELECT foo, bar FROM foo;'\n\nYou can also select from mutliple tables::\n\n >>> str(sql.Select('*', sets=['foo', 'bar']))\n 'SELECT * FROM foo , bar;'\n\n\nIf you want to restrict your select, all common clauses are available::\n\n >>> str(sql.Select('*', ['foo', 'bar'], where='a = %s', group='foo',\n ... order='-bar', limit=10, offset=20))\n 'SELECT * FROM foo , bar WHERE a = %s GROUP BY foo ORDER BY bar DESC LIMIT 10 OFFSET 20;'\n\n\nSo far it looks like a rather complicated way of writing SQL. The real power,\nthough, comes from the fact that every aspect of the query object can be\ntweaked.::\n\n >>> q = sql.Select()\n >>> str(q)\n 'SELECT *;'\n >>> q.what = 'foo'\n >>> q.sets = 'this'\n >>> q.sets.join('other', sql.INNER)\n \n >>> q.where = 'bar = %s'\n >>> q.limit = 2\n >>> str(q)\n 'SELECT foo FROM this INNER JOIN other WHERE bar = %s LIMIT 2;'\n\nNow let's take a look at individual clauses. \n\nThe ``where`` attribute is represented by a ``sqlize_pg.builder.Where`` object,\nwhich supports a few handy operators for adding conditions::\n\n >>> q = sql.Select()\n >>> q.where = 'foo = %s'\n >>> q.where &= 'bar = %s'\n >>> q.where |= 'foo = bar'\n >>> str(q)\n 'SELECT * WHERE foo = %s AND bar = %s OR foo = bar;'\n\nThe ``&=`` and ``|=`` have method aliases. Main advantage is that methods are\nchainable. The above example can be rewritten as::\n\n >>> q = sql.Select()\n >>> q.where = 'foo = %s'\n >>> q.where.and_('bar = %s').or_('foo = bar')\n \n >>> str(q)\n 'SELECT * WHERE foo = %s AND bar = %s OR foo = bar;'\n\nNote the underscore. We can't use method names that look like built-in\noperators.\n\nThe ``sets`` attribute is represented by a ``sqlize_pg.builder.From`` object. It\nhas a few utility methods which you can use to add and join other tables::\n\n >>> q = sql.Select()\n >>> q.sets = 'foo'\n >>> q.sets.append('bar')\n \n >>> str(q)\n 'SELECT * FROM foo , bar;'\n\n >>> q = sql.Select()\n >>> q.sets = 'foo'\n >>> q.sets.join('bar', sql.NATURAL)\n \n >>> str(q)\n 'SELECT * FROM foo NATURAL JOIN bar;'\n\nThere is no direct support for aggregates. Instead, you write raw SQL.::\n\n >>> q = sql.Select('COUNT(*) as count', sets='foo', group='bar')\n >>> str(q)\n 'SELECT COUNT(*) as count FROM foo GROUP BY bar;'\n\nThis is intentional. We wanted sqlize-pg to be as true to SQL as possible, and not\nget in your way.\n\nApart from selecting, sqlize-pg supports inserts, updates, deletion, and\nreplacement.\n\nInserts look like this::\n\n >>> q = sql.Insert('foo', '%s, %s, %s')\n >>> str(q)\n 'INSERT INTO foo VALUES (%s, %s, %s);'\n\nYou can also specify columns::\n\n >>> q = sql.Insert('foo', '%s, %s, %s', ('foo', 'bar', 'baz'))\n >>> str(q)\n 'INSERT INTO foo (foo, bar, baz) VALUES (%s, %s, %s);'\n\nIf you omit the values, the query will contain named placeholders::\n\n >>> q = sql.Insert('foo', cols=('foo', 'bar', 'baz'))\n >>> str(q)\n 'INSERT INTO foo (foo, bar, baz) VALUES (:foo, :bar, :baz);'\n\nReplacing is similar to inserting, but uses ``Replace`` class instead::\n\n >>> q = sql.Replace('foo', constraints=['id'], cols=['id', 'name'])\n >>> str(q)\n 'INSERT INTO foo (id, name) VALUES (%(id)s, %(name)s) ON CONFLICT (id) DO UPDATE SET id = %(id)s, name = %(name)s;'\n\nThe update query looks like this::\n\n >>> q = sql.Update('foo', 'bar = %s', baz='%s')\n >>> str(q)\n 'UPDATE foo SET baz = %s WHERE bar = %s;'\n\nThe second argument is the same as ``where`` in ``Select()``. It can be\nmodified after initialization::\n\n >>> q = sql.Update('foo', baz='%s')\n >>> q.where &= 'foo = %s'\n >>> q.where |= 'bar = %s'\n >>> str(q)\n 'UPDATE foo SET baz = %s WHERE foo = %s OR bar = %s;'\n\nAny keyword arguments passed to ``Update()`` will be converted to ``SET``\nclauses.\n\nDeleting rows can be accomplished using the ``Delete()`` class.::\n\n >>> q = sql.Delete('foo', 'bar = %s')\n >>> str(q)\n 'DELETE FROM foo WHERE bar = %s;'\n\nAs with ``Update()``, the second argument is a ``where`` clause, and can be\nmanipulated.\n\nMore docs, please!\n==================\n\nUnfortunately, there are currently no docs apart from this introduction. I hope\nthat codebase is not too difficult to follow, though, so if you can't wait, you\ncan peek into the source files.\n\nComparison to other libraries\n=============================\n\nTODO\n\nReporting bugs\n==============\n\nReport all bugs and feature requests to our `issue tracker`_.\n\n\n_issue tracker: https://github.com/Outernet-Project/sqlize-pg/issues", "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/Outernet-project/sqlize-pg", "keywords": "sql query builder", "license": "GPLv3", "maintainer": null, "maintainer_email": null, "name": "sqlize-pg", "package_url": "https://pypi.org/project/sqlize-pg/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/sqlize-pg/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/Outernet-project/sqlize-pg" }, "release_url": "https://pypi.org/project/sqlize-pg/1.0/", "requires_dist": null, "requires_python": null, "summary": "Lightweight SQL query builder", "version": "1.0" }, "last_serial": 2045629, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "ae188e3052271269674fda425ab5b067", "sha256": "d9cecabca4c9e237ddf98e73de4246e4ba95ff10ea263c83581eae1c4f941931" }, "downloads": -1, "filename": "sqlize-pg-0.1.tar.gz", "has_sig": false, "md5_digest": "ae188e3052271269674fda425ab5b067", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6918, "upload_time": "2015-11-25T16:03:01", "url": "https://files.pythonhosted.org/packages/f8/2d/975bb36dbe868c10b6d82bbc46178a14bf2581e6e2aca1922305ddbf7f97/sqlize-pg-0.1.tar.gz" } ], "1.0": [ { "comment_text": "", "digests": { "md5": "2ac771fd5d7d3d105f91c326137c637e", "sha256": "3a431f69cdd379351158eb8d58db329badab5f62cbaac361c43ec6ac8aac27b4" }, "downloads": -1, "filename": "sqlize-pg-1.0.tar.gz", "has_sig": false, "md5_digest": "2ac771fd5d7d3d105f91c326137c637e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21443, "upload_time": "2016-04-04T19:49:01", "url": "https://files.pythonhosted.org/packages/dd/49/7c5aa92d0afee631114add0d2cf40bd89cfb2f7ada6ed5c83d470f7ca0fa/sqlize-pg-1.0.tar.gz" }, { "comment_text": "", "digests": { "md5": "eaa2bc9f9a5e964e7fc68ec506e4c725", "sha256": "2d996ccc840469b1fd16ae140d8c7a4b3c4e39db31f1aa0a1d0345c896a85031" }, "downloads": -1, "filename": "sqlize-pg-1.0.zip", "has_sig": false, "md5_digest": "eaa2bc9f9a5e964e7fc68ec506e4c725", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 25236, "upload_time": "2016-04-04T19:49:12", "url": "https://files.pythonhosted.org/packages/af/77/edce4011221704c1fc740e4dfe0550ab91829f97ed7e8a50fb89f1aecf48/sqlize-pg-1.0.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "2ac771fd5d7d3d105f91c326137c637e", "sha256": "3a431f69cdd379351158eb8d58db329badab5f62cbaac361c43ec6ac8aac27b4" }, "downloads": -1, "filename": "sqlize-pg-1.0.tar.gz", "has_sig": false, "md5_digest": "2ac771fd5d7d3d105f91c326137c637e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21443, "upload_time": "2016-04-04T19:49:01", "url": "https://files.pythonhosted.org/packages/dd/49/7c5aa92d0afee631114add0d2cf40bd89cfb2f7ada6ed5c83d470f7ca0fa/sqlize-pg-1.0.tar.gz" }, { "comment_text": "", "digests": { "md5": "eaa2bc9f9a5e964e7fc68ec506e4c725", "sha256": "2d996ccc840469b1fd16ae140d8c7a4b3c4e39db31f1aa0a1d0345c896a85031" }, "downloads": -1, "filename": "sqlize-pg-1.0.zip", "has_sig": false, "md5_digest": "eaa2bc9f9a5e964e7fc68ec506e4c725", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 25236, "upload_time": "2016-04-04T19:49:12", "url": "https://files.pythonhosted.org/packages/af/77/edce4011221704c1fc740e4dfe0550ab91829f97ed7e8a50fb89f1aecf48/sqlize-pg-1.0.zip" } ] }