{ "info": { "author": "Paul J. Davis", "author_email": "paul.joseph.davis@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "Sheba SQL\n=========\n\nSQL management for people that don't mind SQL.\n\nMotivation\n----------\n\nI can write SQL faster than I can figure out the various library and ORM\nabstraction layers. Writing SQL directly in code is pretty disgusting. So\nI stole an idea from the `Axamol SQL Library`_ and along with a couple updates\nhave created this library.\n\nWhat is it?\n-----------\n\nFirst, we'll consider some basic query definitions::\n\n >>> queries = \"\"\"\n ... name: create_roles_table\n ... type: update\n ... sql: |\n ... CREATE TABLE roles\n ... (\n ... scene text,\n ... name text,\n ... actor text,\n ... UNIQUE(scene, name)\n ... )\n ... ---\n ... name: add_role\n ... type: update\n ... sql: | \n ... INSERT\n ... INTO roles(scene, name, actor)\n ... VALUES (${scene}, ${name}, ${actor})\n ... ---\n ... name: list_roles\n ... sql: |\n ... SELECT name,\n ... actor\n ... FROM roles\n ... ORDER BY\n ... name ASC\n ... ---\n ... name: get_role_attr\n ... sql: |\n ... SELECT ${col | ident}\n ... FROM roles\n ... WHERE name = ${name}\n ... \"\"\"\n >>>\n\nThis is a YAML_ file that defines a couple queries for working with a simple\ntable that lists scenes, roles, and actors. Generally, you'll want to define\nyour queries in a file in your Python package and use the static method\n``sheba.Library.from_file(path)`` to load the queries. \n\nNow, to use these in some code::\n\n >>> import sheba\n >>> conn = sheba.connect(queries, driver='sqlite3', args=(':memory:',))\n\nNow that we have a connection, lets create the roles table::\n\n >>> conn.u.create_roles_table()\n -1\n\nThe ``-1`` is due to DDL statements not returning row information. I could\ntechnically create a third class of statement types so avoid this, but in\nthe not doctest world you can just ignore that return value.\n\nNext we'll insert a couple rows::\n\n >>> conn.u.add_role(scene=\"Parrot Sketch\", name=\"MR PRALINE\", actor=\"John Cleese\")\n 1\n >>> conn.u.add_role(scene=\"Parrot Sketch\", name=\"SHOP OWNER\", actor=\"Machale Palin\")\n 1\n >>> conn.u.add_role(scene=\"Parrot Sketch\", name=\"DEAD PARROT\", actor=\"Fake Parrot\")\n 1\n\nYep, it's that simple. And lastly, we'll list the roles in the table::\n\n >>> for row in conn.q.list_roles():\n ... print \"Name: %(name)s Actor: %(actor)s\" % row\n ...\n Name: DEAD PARROT Actor: Fake Parrot\n Name: MR PRALINE Actor: John Cleese\n Name: SHOP OWNER Actor: Machale Palin\n\nAs they say, \"Wicked awesome.\"\n\nPossible Query Attributes\n-------------------------\n\nThe example above only used ``name``, ``type``, and ``sql``. Only ``name`` and\n``sql`` are absolutely required. The full list of attributes is:\n\n* ``name`` - The name used to reference this query from Python\n* ``desc`` - An explanation of the query for documentation.\n* ``type`` - ``query`` or ``update``. Defaults to ``query``.\n* ``dbs`` - A list of database names that this SQL will work with. The default\n value is None which is interpreted as \"Use this query when no SQL\n has been defined for the current connections database connection.\"\n* ``sql`` - The actual query. SQL is passed through Mako with access to\n any parameter names that were provide to the query. To bind\n a parameter in a query, simply print the value with standard\n Mako syntax like ${my_parameter_name}. Sheba will automatically\n replace it with the proper bind variable syntax and pass the\n supplied value onto the database connection.\n\n.. note::\n\n It may appear at first glance that the dynamic queries are writing\n parameter values directly into the SQL. They are *NOT*. The actual\n values passed along into the template context are UUID's that will\n be replaced with bind parameters syntax appropriate to your database\n driver. If you're asking yourself, \"What if I do want the actual value?\"\n you should go fix all of your SQL injection vulnerabilities.\n\nIdentifiers in SQL\n------------------\n\nIf you're feeling particularly precocious there's support for dynamically\nsetting identifier names in SQL statements.\n\nGiven the following YAML query::\n\n name: get_role_attr\n sql: |\n SELECT ${col | ident}\n FROM roles\n WHERE name = ${name}\n\nYou can then execute this query like such::\n\n >>> for row in conn.q.get_role_attr({\"col\": \"actor\", \"name\": \"MR PRALINE\"}):\n ... print \"%(actor)s\" % row\n ...\n John Cleese\n\nSpecifying Connection Details\n-----------------------------\n\nInstead of specifying your database connection details in code you can instead\ncreate a document at the top of your YAML file that lists the parameters to\nuse when connection to the database. These settings are labeled with a name\nthat can be used to refer to a particular config. For instance::\n\n >>> yaml = \"\"\"\\\n ... name: dev\n ... type: connection\n ... driver: sqlite3\n ... args: [\":memory:\"]\n ... ---\n ... name: prod\n ... type: connection\n ... driver: sqlite3\n ... args: [\"/path/to/prod.db\"]\n ... ---\n ... name: create_table\n ... type: update\n ... sql: CREATE TABLE foo(a int primary key);\n ... ---\n ... name: insert_a\n ... type: update\n ... sql: INSERT INTO foo(a) values(3);\n ... ---\n ... name: get_a\n ... sql: SELECT a from foo where a = 3;\n ... \"\"\"\n >>> conn = sheba.connect(yaml, \"dev\")\n >>> conn.u.create_table()\n -1\n >>> conn.u.insert_a()\n 1\n >>> conn.q.get_a().fetchone()[\"a\"]\n 3\n\nLicense\n-------\n\nReleased under the MIT license. See the LICENSE file for more details.\n\n.. _`Axamol SQL Library`: http://www.slamb.org/projects/axamol/sql-library/\n.. _YAML: http://yaml.org/", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/davisp/sheba", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "sheba", "package_url": "https://pypi.org/project/sheba/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/sheba/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/davisp/sheba" }, "release_url": "https://pypi.org/project/sheba/0.0.7/", "requires_dist": null, "requires_python": null, "summary": "Sheba SQL - SQL for normal people.", "version": "0.0.7" }, "last_serial": 799488, "releases": { "0.0.2": [ { "comment_text": "", "digests": { "md5": "04530140a2631370c6e46be45b202510", "sha256": "80d4b12b124b55c32378490f47de8ab3a6f3d5614a5e143fd89565eb2c2ad5dc" }, "downloads": -1, "filename": "sheba-0.0.2.tar.gz", "has_sig": false, "md5_digest": "04530140a2631370c6e46be45b202510", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18130, "upload_time": "2010-04-15T22:32:34", "url": "https://files.pythonhosted.org/packages/e8/6a/0c2586009494f5e4a1c36d72f5ca3559e935ede19db74fad61a37d380a9b/sheba-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "bc796f696614acadfb59233254aa9c98", "sha256": "727cd31bd312c70feec4d7ed06c0c85b1c0d6d964bbb8ab80f980d081c9efd05" }, "downloads": -1, "filename": "sheba-0.0.3.tar.gz", "has_sig": false, "md5_digest": "bc796f696614acadfb59233254aa9c98", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19474, "upload_time": "2010-04-19T17:04:16", "url": "https://files.pythonhosted.org/packages/12/4a/b4bc76c967eccce418d00acc2f38fcf93da550795656061fe80b35afe0f4/sheba-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "aaf5f637ce178fc27e39d354df97cf88", "sha256": "9addb5d657e90daf9839a58dd6b2512f7f7def39cd254f52b79475936b1c4465" }, "downloads": -1, "filename": "sheba-0.0.4.tar.gz", "has_sig": false, "md5_digest": "aaf5f637ce178fc27e39d354df97cf88", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19561, "upload_time": "2010-04-19T22:43:07", "url": "https://files.pythonhosted.org/packages/31/b1/84f315a5a004a9bcc3eace73b4d1593b873285b6b4a1b75f818389dc7570/sheba-0.0.4.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "fd1ab923abe93941f459dd5ee41bcc05", "sha256": "c7f55e7b5ee5d0d20dd7c8ffbcf8c4d23dbcdbf0c81c31f0f543432e6b277800" }, "downloads": -1, "filename": "sheba-0.0.5.tar.gz", "has_sig": false, "md5_digest": "fd1ab923abe93941f459dd5ee41bcc05", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19564, "upload_time": "2010-04-21T22:11:22", "url": "https://files.pythonhosted.org/packages/c5/ec/058ead157c69d072e34fad1ac6ee5961219369e5d71102a6b27fbad8bd42/sheba-0.0.5.tar.gz" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "43731671b9d164a20c5a3ef9094c8edb", "sha256": "75274709fd208e059a596c83bc098093ccaa2dae171f008d95280afc5ef55930" }, "downloads": -1, "filename": "sheba-0.0.6.tar.gz", "has_sig": false, "md5_digest": "43731671b9d164a20c5a3ef9094c8edb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22058, "upload_time": "2010-04-22T20:43:34", "url": "https://files.pythonhosted.org/packages/ff/8f/fbfabd3051f9cee7c3c7d906b22112fae7e4f17adb498a255686da0961b2/sheba-0.0.6.tar.gz" } ], "0.0.7": [ { "comment_text": "", "digests": { "md5": "5bbbea55740a10600a5eaba0cef47460", "sha256": "58a381a1b718a28167af0ecf19511188a40c6a137c3682c40406e015a73815bd" }, "downloads": -1, "filename": "sheba-0.0.7.tar.gz", "has_sig": false, "md5_digest": "5bbbea55740a10600a5eaba0cef47460", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22255, "upload_time": "2010-07-22T01:21:11", "url": "https://files.pythonhosted.org/packages/bd/b8/5ca5ff8c09344b84a176f34859cc66e8d48fae0d4fb4f7896d3124137a5c/sheba-0.0.7.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5bbbea55740a10600a5eaba0cef47460", "sha256": "58a381a1b718a28167af0ecf19511188a40c6a137c3682c40406e015a73815bd" }, "downloads": -1, "filename": "sheba-0.0.7.tar.gz", "has_sig": false, "md5_digest": "5bbbea55740a10600a5eaba0cef47460", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22255, "upload_time": "2010-07-22T01:21:11", "url": "https://files.pythonhosted.org/packages/bd/b8/5ca5ff8c09344b84a176f34859cc66e8d48fae0d4fb4f7896d3124137a5c/sheba-0.0.7.tar.gz" } ] }