{ "info": { "author": "Barbaros YILDIRIM", "author_email": "barbarosaliyildirim@gmail.com", "bugtrack_url": null, "classifiers": [ "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python :: 2.7" ], "description": "python-sqldict\r\n==============\r\n\r\n.. image:: https://travis-ci.org/RedXBeard/python-sqldict.svg?branch=master\r\n :target: https://travis-ci.org/RedXBeard/python-sqldict \r\n :alt: Build\r\n.. image:: https://pypip.in/download/sqltodict/badge.svg\r\n :target: https://pypi.python.org/pypi//sqltodict/\r\n :alt: Downloads\r\n.. image:: https://pypip.in/version/sqltodict/badge.svg\r\n :target: https://pypi.python.org/pypi/sqltodict/\r\n :alt: Latest Version\r\n.. image:: https://pypip.in/py_versions/sqltodict/badge.svg\r\n :target: https://pypi.python.org/pypi/sqltodict/\r\n :alt: Supported Python versions\r\n.. image:: https://pypip.in/license/sqltodict/badge.svg\r\n :target: https://pypi.python.org/pypi/sqltodict/\r\n :alt: License\r\n\r\nRaw SQL results returns as dictionary.\r\n\r\nDevelopers who has lots of works on databases, sometimes, especially written raw sql result or in other words selects become to much to handle, so to play with the result of that sqls become pain; columns has to be remembered which index of result list refers which column etc. (ORM usage is fix this issue but has consequences so even if you are using ORM sometimes as said writing raw sqls preferred)\r\n\r\nTo have a key value pair like dictionaries for sql results will be much more useful, and the pain will become less.\r\n\r\nInstallation\r\n------------\r\nUsing pip library will be installed as following\r\n\r\n.. code-block:: bash\r\n\r\n $ pip install sqltodict\r\n $ pip install psycopg2\r\n $ pip install mysql-connector-repackaged\r\n\r\nUsage for PostgreSQL\r\n--------------------\r\nTo play with postgress database, required connection is as following;\r\n\r\n.. code-block:: python\r\n\r\n : from sqltodict.connections.postgresqlconnection import PostgreSQLConnection\r\n\r\n\r\nThere are two ways to make class one is giving all required attributes for making the connection;\r\n\r\n.. code-block:: python\r\n\r\n : pc = PostgreSQLConnection(sql=\"\"\"select id, code\r\n from product\r\n limit 10\r\n \"\"\",\r\n database='template1'\r\n user='dbuser'\r\n host='localhost'\r\n password='dbpass',\r\n port=5433)\r\n\r\n\r\nOther one is; cursor will be already generated and it could be enough to making the class;\r\n\r\n.. code-block:: python\r\n\r\n : import psycopg2\r\n : conn = psycopg2.connect(dbname='template1',\r\n user='dbuser',\r\n host='localhost',\r\n password='dbpass',\r\n port=5433)\r\n : cursor = conn.cursor()\r\n : pc = PostgreSQLConnection(sql=\"\"\"select id, code\r\n from product\r\n limit 10\r\n \"\"\",\r\n cursor=cursor)\r\n\r\n\r\nExecution is simple as it is;\r\n\r\n.. code-block:: python\r\n\r\n : pc.execute_sql()\r\n\r\n\r\nThe result will as following, as default sql select result which is sometimes so hard to continue working.\r\n\r\n.. code-block:: python\r\n\r\n : pc.result\r\n [(62392, '4YAL61165JW'),\r\n (41308, 'Y14FCD010394'),\r\n (61397, '4YAL16490IK'),\r\n (4396, 'W2WCR0040'),\r\n (61696, '4YAK71063AA'),\r\n (57895, '4YAK38077PW'),\r\n (64853, 'V0400710218'),\r\n (61870, 'Y14LGD021110'),\r\n (55054, '4YAM19187LK'),\r\n (61027, '4YAM19698LK')]\r\n\r\n\r\nFor dictionary conversion the sql result will be following, as understandable list.\r\n\r\n.. code-block:: python\r\n\r\n : pc.execute_return_as_dict()\r\n [{'code': '4YAL61165JW', 'id': 62392},\r\n {'code': 'Y14FCD010394', 'id': 41308},\r\n {'code': '4YAL16490IK', 'id': 61397},\r\n {'code': 'W2WCR0040', 'id': 4396},\r\n {'code': '4YAK71063AA', 'id': 61696},\r\n {'code': '4YAK38077PW', 'id': 57895},\r\n {'code': 'V0400710218', 'id': 64853},\r\n {'code': 'Y14LGD021110', 'id': 61870},\r\n {'code': '4YAM19187LK', 'id': 55054},\r\n {'code': '4YAM19698LK', 'id': 61027}]\r\n\r\n\r\nUsage for MYSQL\r\n---------------\r\nPlaying with an mysql database there are slightly differences; starts with import;\r\n\r\n.. code-block:: python\r\n\r\n : from sqltodict.connections.mysqlconnection import MYSQLConnection\r\n\r\n\r\nThere are two ways again to make the class usable;\r\n\r\n.. code-block:: python\r\n\r\n : mc = MYSQLConnection(sql=\"\"\"select id, code\r\n from product\r\n limit 10\r\n \"\"\",\r\n database='template1'\r\n user='dbuser'\r\n host='localhost'\r\n password='dbpass',\r\n port=3306)\r\n\r\n\r\n... or in other way is as mentioned before, as following;\r\n\r\n.. code-block:: python\r\n\r\n : import mysql.connector\r\n : conn = mysql.connector.connect(user='root',\r\n password='',\r\n host='localhost',\r\n database='template1',\r\n port=3306)\r\n : cursor = conn.cursor()\r\n : mc = MYSQLConnection(sql=\"\"\"select id, code\r\n from product\r\n limit 10\r\n \"\"\",\r\n cursor=cursor)\r\n\r\n\r\nExecution is simple if result is wanted as default one;\r\n\r\n.. code-block:: python\r\n\r\n : mc.execute_sql()\r\n : mc.result\r\n [(62392, '4YAL61165JW'),\r\n (41308, 'Y14FCD010394'),\r\n (61397, '4YAL16490IK'),\r\n (4396, 'W2WCR0040'),\r\n (61696, '4YAK71063AA'),\r\n (57895, '4YAK38077PW'),\r\n (64853, 'V0400710218'),\r\n (61870, 'Y14LGD021110'),\r\n (55054, '4YAM19187LK'),\r\n (61027, '4YAM19698LK')]\r\n\r\nIf dictionary type of result is requested, directly;\r\n\r\n.. code-block:: python\r\n\r\n : mc.execute_return_as_dict()\r\n [{'code': u'W2WCR0040', 'id': 4396},\r\n {'code': u'Y14FCD010394', 'id': 41308},\r\n {'code': u'4YAM19187LK', 'id': 55054},\r\n {'code': u'4YAK38077PW', 'id': 57895},\r\n {'code': u'4YAM19698LK', 'id': 61027},\r\n {'code': u'4YAL16490IK', 'id': 61397},\r\n {'code': u'4YAK71063AA', 'id': 61696},\r\n {'code': u'Y14LGD021110', 'id': 61870},\r\n {'code': u'4YAL61165JW', 'id': 62392},\r\n {'code': u'V0400710218', 'id': 64853}]", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/RedXBeard/python-sqldict/tarball/1.2", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/RedXBeard/python-sqldict", "keywords": "sql,dict,sql to dict,select results as dict,sql to dictionary,postgresql select as dictionary,postgress results as dict", "license": "UNKNOWN", "maintainer": "", "maintainer_email": "", "name": "sqltodict", "package_url": "https://pypi.org/project/sqltodict/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/sqltodict/", "project_urls": { "Download": "https://github.com/RedXBeard/python-sqldict/tarball/1.2", "Homepage": "https://github.com/RedXBeard/python-sqldict" }, "release_url": "https://pypi.org/project/sqltodict/1.2/", "requires_dist": null, "requires_python": null, "summary": "Raw sql results returns as dictionary.", "version": "1.2" }, "last_serial": 1251964, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "792b346e5f199e45083ede5fe5b4f068", "sha256": "4b722f8725b1688d062c031a5ca467a14141d76ebfbfb329df90b28cba432f48" }, "downloads": -1, "filename": "sqltodict-1.0.tar.gz", "has_sig": false, "md5_digest": "792b346e5f199e45083ede5fe5b4f068", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4173, "upload_time": "2014-09-09T12:38:09", "url": "https://files.pythonhosted.org/packages/f8/2c/87efe412488793914ed4ef881277147163a46bd62feb48d158337c7a3d53/sqltodict-1.0.tar.gz" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "de99c73b2a0daf9b0a71a2547fc785e9", "sha256": "be56d8493b7debf0000ed4248cc5a49b4226f0cb66481cb714e61ddc2460899f" }, "downloads": -1, "filename": "sqltodict-1.2.tar.gz", "has_sig": false, "md5_digest": "de99c73b2a0daf9b0a71a2547fc785e9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4156, "upload_time": "2014-09-09T13:27:28", "url": "https://files.pythonhosted.org/packages/f9/28/dd6110055bc56772091376258d9e76b28b47cf515981f2b0224e500a1597/sqltodict-1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "de99c73b2a0daf9b0a71a2547fc785e9", "sha256": "be56d8493b7debf0000ed4248cc5a49b4226f0cb66481cb714e61ddc2460899f" }, "downloads": -1, "filename": "sqltodict-1.2.tar.gz", "has_sig": false, "md5_digest": "de99c73b2a0daf9b0a71a2547fc785e9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4156, "upload_time": "2014-09-09T13:27:28", "url": "https://files.pythonhosted.org/packages/f9/28/dd6110055bc56772091376258d9e76b28b47cf515981f2b0224e500a1597/sqltodict-1.2.tar.gz" } ] }