{ "info": { "author": "Hansheng Zhao", "author_email": "copyrighthero@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Intended Audience :: End Users/Desktop", "Intended Audience :: Information Technology", "Intended Audience :: Science/Research", "Intended Audience :: System Administrators", "License :: OSI Approved :: BSD License", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Topic :: Communications", "Topic :: Database", "Topic :: Internet", "Topic :: Software Development", "Topic :: System", "Topic :: Utilities" ], "description": "###############\nDecibel Project\n###############\n\n`README\u4e2d\u6587\u6587\u6863 `_ | `SQLite `_ | `PEP-249 DB-API 2.0 `_ | `Python Docs: sqlite3 `_ | `MySQL Connectors `_\n\nAbout the Decibel Library\n=========================\n\nThe Decibel library is a Python DB-API database manager, or to be more precise, a thin wrapper. It exposes three methods besides the database instance: `reg` for registering a named statement,`run` for running a registered statement a single time or multiple times, and `__call__` method for executing a query.\n\nThe wrapper can be helpful for it can memorize a statement with a short-hand key, user/developer can then execute the statement with the key instead of the full-blown statement string. This way, the statements can be stored and managed else where centrally, ie. `config.ini`. So any updates to the statements does not necessarily break the program's functionality. If you are interested, the `Utilize Library `_ provides user with config/settings central management functionality, and it uses `Decibel` to provide user with database management.\n\nBesides the statement management, the library also features a `Result` class used to hold query results. It is a subclass of `list` with two properties: `lastrowid` and `rowcount`.\n\nSince all queries executed with `Decibel` class are automatically committed to the database, user don't have to worry about data loss; however, all the query results are fetched at once using `fetchall` method on the database cursors, this library is not particularly suited for queries with very very long results.\n\nAll the database methods are still available to use, so the user can do more.\n\nHow to Use Decibel Library\n==========================\n\nAfter installing using `pip install Decibel`, simply import Decibel, pass in the database instance as the first parameter, and optionally a `dict` of `key - statement` pairs for the second parameter.\n\nNew statement can be registered using `reg` method, it takes a string key and a string statement as its arguments, and persist them in the memory. Optionally, it takes arbitrarily keyword arguments (`**kwargs`), and treat them as `key - statement` pairs, and persist them in its memory.\n\nTo execute a saved statement, one can simply invoke the `run` method, with the first parameter being statement key, and the second being a tuple/list of arguments. Optionally, if the third argument is provided as `True`, it will expect the values to be tuple/list of tuple/list of arguments, and execute the saved query on each of the items.\n\nA query can be executed without being saved simply by calling directly on the instance itself (`__call__` method), the second argument and the third behaves the same as `run` method.\n\n.. code-block:: python\n\n from mysql.connector import connect as mysql\n from sqlite3 import connect as sqlite\n from decibel import Decibel\n\n # create database instances as usual\n mysql_db = mysql(host = 'localhost', port = 3306, database = 'test')\n sqlite_db = sqlite(':memory:')\n\n # initialize Decibel with database instance and statement repo\n mysql_dec = Decibel(mysql_db, {\n 'init' : 'create table test (id int(11) not null primary key auto_increment);'\n })\n # register statements for later use with key `insert` and `select_all`\n mysql_dec.reg('insert', 'insert into test values (%s);', select_all = 'select * from test;')\n # run a saved statement\n mysql_dec.run('init') # [], empty results\n # run the saved `insert` statement with values\n res = mysql_dec.run('insert', (100, )) # insert a value with single parameter\n res.lastrowid # 100, get the last row id\n res.rowcount # 1, get the affected row count\n # run the saved statement on multiple statements\n res = mysql_dec.run('insert', [(200, ), (300, )], True) # [[], []]execute many/insert many\n # since executed on many values, each item in the res list is a Result object\n res[0].lastrowid # 200, the first insert command's lastrowid\n res[0].rowcount # 1, the first insert command's rowcount\n res[1].lastrowid # 300, the second insert command's lastrowid\n res[1].rowcount # 1, the second insert command's rowcount\n res = mysql_dec.run('select_all') # [(100, ), (200, ), (300, )] the results\n res.lastrowid # 300, access the lastrowid\n res.rowcount # -1, access query row count\n\n # one can also execute a statement one by calling the object\n res = mysql_dec('select * from test;')\n res.lastrowid # 300, access the lastrowid\n res.rowcount # -1, access query row count\n\n # wrapper also worked on sqlite3 or any DB-API compliant instances\n sqlite_dec = Decibel(sqlite_db)\n sqlite_dec('create table test (id integer not null primary key autoincrement, co);')\n sqlite_dec.reg(insert = 'insert into test values (?, ?);')\n res = sqlite_dec.run('insert', (1, 'content'))\n res.lastrowid # 1\n res.rowcount # 1\n res = sqlite_dec.run('insert', (2, 'content'))\n res.lastrowid # 2\n res.rowcount # 1\n\nDecibel Class API References\n============================\n\nThe Decibel module provides two classes: `Result` and `Decibel`. The `Result` class is a subclass of Python `list` and is used to hold the execution result returned by database cursor; the `Decibel` class is the actual wrapper that manages statements, executions and commits.\n\nResult Class\n------------\n\nA sub class of `list`, with `lastrowid` and `rowcount` properties. it will perform a `fetchall` operation on the cursor passed in, so be aware that this might not be suitable for queries with very very long results.\n\nSignature: `Result(cursor)`\n\n- `instance.lastrowid` property: will give the user the last insertion row id, useful when auto incrementing.\n- `instance.rowcount` property: will give the user how many rows are affected by this query.\n\nDecibel Class\n-------------\n\nThe thin-wrapper manager class for DB-API compliant databases. Three methods were added on the database instances, `reg`, `run` and `__call__`. All the database methods are still available, so the users are not restricted by using this library.\n\nSignature: `Decibel(database, statments = None)`\n\n- `instance.reg(stid = None, stmt = None, **kwargs)`: register a key-statement pair for later use.\n- `instance.run(stid, vaulues = None, many = False)`: execute a saved statement.\n- `isntance(statement, values = None, many = False)`: execute a statement.\n\nLicenses\n========\n\nThis project is licensed under two permissive licenses, please chose one or both of the licenses to your like. Although not necessary, bug reports or feature improvements, attributes to the author(s), information on how this program is used are welcome and appreciated :-) Happy coding\n\n[BSD-2-Clause License]\n\nCopyright 2018 Hansheng Zhao\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n\n2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n[MIT License]\n\nCopyright 2018 Hansheng Zhao\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "https://www.github.com/copyrighthero/Decibel", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://www.github.com/copyrighthero/Decibel", "keywords": "Database Management Thin-wrapper Library", "license": "BSD-2-Clause + MIT", "maintainer": "", "maintainer_email": "", "name": "Decibel", "package_url": "https://pypi.org/project/Decibel/", "platform": "", "project_url": "https://pypi.org/project/Decibel/", "project_urls": { "Download": "https://www.github.com/copyrighthero/Decibel", "Homepage": "https://www.github.com/copyrighthero/Decibel", "Source": "https://www.github.com/copyrighthero/Decibel" }, "release_url": "https://pypi.org/project/Decibel/1.0.1/", "requires_dist": null, "requires_python": "", "summary": "Python database management thin wrapper.", "version": "1.0.1" }, "last_serial": 3699223, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "bf7f9d49bf286ef876485a36ba5c03d2", "sha256": "872c53a549ab99b6bf8b1b262558917954826f30dca2d2a7c250173698b1f772" }, "downloads": -1, "filename": "Decibel-1.0.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "bf7f9d49bf286ef876485a36ba5c03d2", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 10903, "upload_time": "2018-03-20T21:48:11", "url": "https://files.pythonhosted.org/packages/fb/cd/3974875acd61ead49453cb2ef1d13ece08654a98ddf7aba95f557f128f38/Decibel-1.0.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "52b7dc0ea8c9ce3cca200626c9b9dbc5", "sha256": "cdfff1478755408895bb25f701f47962320190dd388003cd920570680293e465" }, "downloads": -1, "filename": "Decibel-1.0.0.tar.gz", "has_sig": false, "md5_digest": "52b7dc0ea8c9ce3cca200626c9b9dbc5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8025, "upload_time": "2018-03-20T21:48:12", "url": "https://files.pythonhosted.org/packages/ca/79/c9808353b793c800c07a4da607196d2eefded0ae2f42545700167935236b/Decibel-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "68023111b4c0e7d91de7ed1680c3ea3a", "sha256": "c75045e32b02c44175e79ea9fcf896fe2bf380893b9a6c39a0b3d9d48df6dc57" }, "downloads": -1, "filename": "Decibel-1.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "68023111b4c0e7d91de7ed1680c3ea3a", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 11102, "upload_time": "2018-03-23T14:42:07", "url": "https://files.pythonhosted.org/packages/6d/0a/5ae83dae8e4ba6c60acda1ae92f1dc109171d3f50fb8e7f3b2a91267ffb0/Decibel-1.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0563ec3242eb9716b0ef9704c98e7e3f", "sha256": "e166bc591191b7849f7fea5be4937ee90dc24ec445cd249aa78d3ae60c84596e" }, "downloads": -1, "filename": "Decibel-1.0.1.tar.gz", "has_sig": false, "md5_digest": "0563ec3242eb9716b0ef9704c98e7e3f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9899, "upload_time": "2018-03-23T14:42:08", "url": "https://files.pythonhosted.org/packages/42/09/e4ebab13ac27ea2cdfed61dcd8348fd2c29a2b8fbca001b9d10131b6db99/Decibel-1.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "68023111b4c0e7d91de7ed1680c3ea3a", "sha256": "c75045e32b02c44175e79ea9fcf896fe2bf380893b9a6c39a0b3d9d48df6dc57" }, "downloads": -1, "filename": "Decibel-1.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "68023111b4c0e7d91de7ed1680c3ea3a", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 11102, "upload_time": "2018-03-23T14:42:07", "url": "https://files.pythonhosted.org/packages/6d/0a/5ae83dae8e4ba6c60acda1ae92f1dc109171d3f50fb8e7f3b2a91267ffb0/Decibel-1.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0563ec3242eb9716b0ef9704c98e7e3f", "sha256": "e166bc591191b7849f7fea5be4937ee90dc24ec445cd249aa78d3ae60c84596e" }, "downloads": -1, "filename": "Decibel-1.0.1.tar.gz", "has_sig": false, "md5_digest": "0563ec3242eb9716b0ef9704c98e7e3f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9899, "upload_time": "2018-03-23T14:42:08", "url": "https://files.pythonhosted.org/packages/42/09/e4ebab13ac27ea2cdfed61dcd8348fd2c29a2b8fbca001b9d10131b6db99/Decibel-1.0.1.tar.gz" } ] }