{ "info": { "author": "Paulo Phagula", "author_email": "pphagula@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Database", "Topic :: Software Development", "Topic :: Software Development :: Libraries", "Topic :: Utilities" ], "description": "ezrecords: SQL for Humans\u2122 Enhanced\n====================================\n\n.. image:: https://img.shields.io/github/release/dareenzo/ezrecords.svg\n :target: https://github.com/dareenzo/ezrecords/releases\n :alt: Latest Version\n\n.. image:: https://travis-ci.org/dareenzo/ezrecords.svg?branch=master\n :target: https://travis-ci.org/dareenzo/ezrecords\n :alt: Build\n\n.. image:: https://coveralls.io/repos/github/dareenzo/ezrecords/badge.svg?branch=master\n :target: https://coveralls.io/github/dareenzo/ezrecords?branch=master\n :alt: Coverage\n\n.. image:: https://img.shields.io/github/license/dareenzo/ezrecords.svg\n :target: https://github.com/dareenzo/ezrecords/blob/master/LICENSE\n :alt: License\n\n.. _LICENSE: http://www.github.com/dareenzo/ezrecords/blob/master/LICENSE\n.. _records: https://github.com/kennethreitz/records\n.. _ezsql: https://github.com/ezSQL/ezSQL\n.. _wpdb: https://codex.wordpress.org/Class_Reference/wpdb\n.. _SQLAlchemy: http://www.sqlalchemy.org\n\n\n**ezrecords is a very simple, but powerful, library for making raw SQL\nqueries to most relational databases.**\n\nezrecords = Kenneth Reitz's `records`_ + Justin Vincent's `ezsql`_ + WordPress' `wpdb`_ - `SQLAlchemy`_.\n\nJust write SQL. No bells, no whistles. This common task can be\nsurprisingly difficult with the standard tools available.\nThis library strives to make this workflow as simple as possible,\nwhile providing an elegant interface to work with your query results.\n\n*Database support includes SQLite, Postgres, and MySQL (drivers not included).*\n\nWhy?\n----\n\n- `records`_ is awesome\n- `ezsql`_ and `wpdb`_ have very nice API, so it makes for an easy transition\n from PHP to Python\n- Our love for crafting well written and performant SQL queries is not questionable,\n but I think a few helpers for some basic DML and recurring queries would help\n- *\"The ORM takes two brilliant ideas and incapacitates them both.\"*,\n said a very wise man. So, as long as possible I want to keep away from\n sqlalchemy or the like.\n\nUsage\n------\n\nAPI\n~~~\n\n.. code:: Python\n\n import logging\n from ezrecords.mysqldb import MySQLDb\n\n logger = logging.getLogger()\n\n # connect\n \u00a0 db = MySQLDb(db_url=\"mysql://root:passwd@127.0.0.1:3306/test\", logger=logger) # logger is optional\n\n # enable debugging - optional\n db.save_queries = True # save queries and execution time\n db.show_sql = True # show SQL code being executed. logger above is required for logging to work\n db.show_errors = True # show errors\n\n create_user_table = \"\"\"\n CREATE TABLE test_user (\n id INT AUTO_INCREMENT NOT NULL,\n username varchar(255) UNIQUE,\n password varchar(255),\n created_at TIMESTAMP,\n created_at_gmt TIMESTAMP,\n PRIMARY KEY(id)\n )\n \"\"\"\n db.query(create_table) # run generic SQL\n\n create_numbers_table = \"\"\"\n DROP TABLE IF EXISTS numbers;\n CREATE TABLE numbers(\n ints int,\n floats float\n );\n \"\"\"\n db.query(create_table_sql)\n\n insert_numbers_sql = \"INSERT INTO numbers (ints, floats) VALUES (%d, %f)\" # DB API only accepts %s, so we replace %d and %f by %s internally\n db.query(insert_numbers_sql, 3, 3.14) # run generic queries with params\n\n # insert records\n db.insert('test_user', username='scott', password='tiger', created_at=datetime.datetime.now())\n db.insert('test_user', {'username': 'JONES', 'password': 'STEEL'})\n\n # bulk_insert records\n db.bulk_insert('test_user', ('username', 'password'), [('scott', 'tiger'), ('JONES', 'STEEL')])\n\n # Update records\n db.update('test_user', {'password': 'shepard'}, {'username': 'scott'})\n\n # Delete records\n db.delete('test_user', {'username': None}) # None is converted to NULL\n\n # Sanitize query\n db.prepare(\"\"\"INSERT INTO postmeta (post_id, meta_key, meta_value) VALUES ( '%d', \"%s\", %%s )')\"\"\", 10, \"Harriet's Adages\", \"WordPress' database interface is like Sunday Morning: Easy.\")\n\n # Call stored procedures\n db.call_procedure('adds', 1, 2)\n\n # Get single variable/value\n db.get_var('SELECT version()')\n\n # Get specific row from many results\n db.get_row('SELECT * FROM test_user', row_offset=1) # if offset not given the first row is returned\n\n # Get specific column from many results\n db.get_col('SELECT username, password FROM test_user', column_offset='password') # offset can be numeric too\n\n # Get results in specific format\n db.get_results('SELECT username, password FROM test_user', 'json')\n # Get last inserted ID from AUTO_INCREMENT/SERIAL fields\n db.insert('test_user', username='scott', password='tiger', created_at=datetime.datetime.now())\n db.last_insert_id\n\n # Get number of affected rows from previus query\n db.delete('test_user')\n db.affected_rows\n\n # Switch to another database\n db.use('information_schema')\n\n # Check query timing\n # execute long running query\n db.last_query_elapsed_time\n\n # Transactions\n # ---\n db.begin_transaction()\n db.commit() # or db.rollback()\n\n # Data export\n rows = db.query('SELECT * FROM table')\n rows.dataset\n rows.export('csv') # yaml, json, xls, xlsx\n\n # Goodies\n db.db_version() # get server version\n db.exists('table') # check if table exists\n db.get_table_names() # get list of tables in database\n db.flush() # clear cache results\n\n\nCLI\n~~~\n\n.. code:: bash\n\n ezrecords -h\n ezrecords \"SELECT version() AS version\" \"json\" --url=\"mysql://root:passwd@127.0.0.1:3306/test\"\n ezrecords \"SELECT version() AS version\" \"json\" --url=\"postgres://postgres:passwd@127.0.0.1:5432/test\"\n ezrecords \"SELECT sqlite_version() AS version\" \"json\" --url=\"sqlite:///:memory:\"\n\nThank you\n----------\nThanks for checking this library out! I hope you find it useful.\n\nOf course, there's always room for improvement. Feel free to\n`open an issue `_\nso we can make **ezrecords** better, faster, and stronger.\n\nDownload and Install\n--------------------\n\nUntil the module is made available on pypi, you can install this module\ndirectly from github with:\n\n``pip install -e git+https://github.com/dareenzo/ezrecords@master#egg=ezrecords``\n\nezrecords runs with **Python 2.7 and 3.5**.\n\nDocumentation Generation\n------------------------\n\n.. code-block:: sh\n\n # edit documentation in _docs\n cd _docs\n make singlehtml\n cd ..\n cp -fR _docs/_build/singlehtml/* docs/\n\n\nCopyright & License\n--------------------\n\nCode and documentation are available according to the MIT License.\n\nSee the `LICENSE`_ file for details.\n\n# Change log\n\nFor a complete view of all the releases, visit the releases page on GitHub:\n[https://github.com/dareenzo/ezrecords/releases](https://github.com/dareenzo/ezrecords/releases)\n\n## v0.3.0 - 2018-05-12\n\nFeatures:\n\n- Added support for SQLite\n\n## v0.2.0 - 2017-05-27\n\nFeatures:\n\n- Bulk insert: `db.bulk_insert('test_user', ('username', 'password'), [('scott', 'tiger'), ('JONES', 'STEEL')])`\n\nFixes:\n\n- Improve documentation\n- Update base records library code\n- Fixes error with getting passing params to query\n- start unquoting username and password as defined in the standard RFC\n\n## v0.1.0 - 2017-01-07\n\n- Initial release", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/dareenzo/ezrecords", "keywords": "database,db,helper,utility,sql", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "ezrecords", "package_url": "https://pypi.org/project/ezrecords/", "platform": "a", "project_url": "https://pypi.org/project/ezrecords/", "project_urls": { "Homepage": "https://github.com/dareenzo/ezrecords" }, "release_url": "https://pypi.org/project/ezrecords/0.3.0/", "requires_dist": null, "requires_python": "", "summary": "SQL for the enhanced.", "version": "0.3.0" }, "last_serial": 3857379, "releases": { "0.3.0": [ { "comment_text": "", "digests": { "md5": "cd53a8bb46beb9761ad4a456217d47bb", "sha256": "f441c549caf59e6bb9b14cf0cdbe84b06c8f61100a9ed64a4f6ab239c68a864a" }, "downloads": -1, "filename": "ezrecords-0.3.0.tar.gz", "has_sig": false, "md5_digest": "cd53a8bb46beb9761ad4a456217d47bb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 182273, "upload_time": "2018-05-12T20:10:34", "url": "https://files.pythonhosted.org/packages/cc/e6/77de2c3228309fd990d0c379ee3345d478aca22795925ef994a3944eed79/ezrecords-0.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "cd53a8bb46beb9761ad4a456217d47bb", "sha256": "f441c549caf59e6bb9b14cf0cdbe84b06c8f61100a9ed64a4f6ab239c68a864a" }, "downloads": -1, "filename": "ezrecords-0.3.0.tar.gz", "has_sig": false, "md5_digest": "cd53a8bb46beb9761ad4a456217d47bb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 182273, "upload_time": "2018-05-12T20:10:34", "url": "https://files.pythonhosted.org/packages/cc/e6/77de2c3228309fd990d0c379ee3345d478aca22795925ef994a3944eed79/ezrecords-0.3.0.tar.gz" } ] }