{ "info": { "author": "Joshua Widrick", "author_email": "jjwidric@buffalo.edu", "bugtrack_url": null, "classifiers": [], "description": "# JDatabase (JDB)\njdatabase package by [Joshua Widrick](https://joshuawidrick.com \"Homepage - Joshua Widrick\")
\n\n**Documentation:** [docs.jwid.co](https://docs.jwid.co/jdatabase \"JDatabase Documentation\")
\n**GitHub (source code):** [GitHub.com/JoshWIdrick/jdb](https://github.com/JoshWidrick/jdb \"JDatabase Source Code\")
\n**Version:** 1.1.1-alpha3
\n**License:** MIT
\n\nFunction / Overview:\n===\nThe function of the jdatabase package is to allow easy and fluid connection, control, and use of MySQL, and \nPostgreSQL database systems through one easy to use, concurrent format. The package also allows for logging of data transactions, \nallowing for database roll-back.
\nThe development of this package has been solely for use in many of [my other projects](https://joshuawidrick.com \"Homepage - Joshua Widrick\"). This package has a lot of default functionality that a normal user will not need. Any feature that you do not need, you can ignore (however understanding it is recommended).
\n\nInstallation:\n===\nThe jdatabase package is available publicly through [PyPi / pip](https://pypi.org/project/jdatabase \"jdatabase on pip\"), so all you need to do is\n`sudo pip install jdatabase`. \nThe package can be updated with \n`sudo pip install jdatabase --upgrade`.
\nFrom source, run\n`sudo python setup.py install`.
\n \nInstantiation:\n===\nThe instantiation of the Jdatabase object requires a host, user, password(passwd), and database name(db). The optional arguments are\ncharset, which defaults to `\"utf8\"`; port, which defaults to `3306`; ssl, which defaults to `True`; and autocommit, which\ndefaults to `True`.
\n```python\nfrom jdatabase import Jdatabase\njdb = Jdatabase(host=\"db_hostname\", user=\"db_username\", passwd=\"db_password\", db=\"db_name\" )\n``` \n\nTable Methods:\n===\n\nget_table_names()\n---\nMethod to get the names of all the tables in the connected database.
\n**Returns a list of str table names.**
\n```python\njdb.get_table_names()\n```\n> Use of this method also updates self.table_names and self.stable_names for self use.
\n##### output:\n```\n['SYSTEM_TABLE', 'table_name', 'table_name2', ...]\n```\n\nget_cleaned_table_names()\n---\nMethod to get the names of all non-system tables in the connected database.
\n**Returns a list of str table names.**
\n```python\njdb.get_cleaned_table_names()\n```\n> This method DOES NOT update self.table_names and self.stable_names.
\n##### output: \n```\n['table_name', 'table_name2', ...]\n```\n\ncheck_for_table(name)\n---\nMethod to check for a table, named name, in the database.
\n**Returns `True` if table found, `False` if not.**
\n```python\njdb.check_for_table(\"table_name\")\n```\n\ncreate_table(name, {column_name:[parms]})\n---\n>> [`create_table_if_false_check()`](#create_table_if_false_checkname-column_nameparms) is recommended for all table creation.
\n\nCreates a table in the database.
\n**Returns the rowcount for the query, should be `0`.**
\n```python\njdb.create_table(\"table_name\", {\"jd\":[\"VARCHAR(128)\", \"PRIMARY KEY\"], \"column_name\":[\"DATATYPE\", \"DEFAULT VALUE\"]})\n```\n```python\n# with auto primary key insertion\njdb.create_table(\"table_name\", {\"column_name\":[\"DATATYPE\", \"DEFAULT VALUE\"], \"column2_name\":[\"DATATYPE\", \"DEFAULT VALUE\"]})\n```\n> The jdatabase package automatically adds a jd column as the primary key column (if a primary key column is not included).
\n\n> The recommend DEFAULT VALUE is `NOT NULL`.
\n\ncreate_table_if_not_exists(name, {column_name:[parms]})\n---\n>> [`create_table_if_false_check()`](#create_table_if_false_checkname-column_nameparms) is recommended for all table creation.
\n\nCreates a table in the database, if the table name is not present in the database, with database level existence check.
\n**Returns the rowcount for the query, should be `0`.**
\n```python\njdb.create_table_if_not_exists(\"table_name\", {\"jd\":[\"VARCHAR(128)\", \"PRIMARY KEY\"], \"column_name\":[\"DATATYPE\", \"DEFAULT VALUE\"]})\n```\n```python\n# with auto primary key insertion\njdb.create_table_if_not_exists(\"table_name\", {\"column_name\":[\"DATATYPE\", \"DEFAULT VALUE\"], \"column2_name\":[\"DATATYPE\", \"DEFAULT VALUE\"]})\n```\n> The jdatabase package automatically adds a jd column as the primary key column (if a primary key column is not included).
\n\n> The recommend DEFAULT VALUE is `NOT NULL`.
\n\ncreate_table_if_false_check(name, {column_name:[parms]})\n---\nCreates a table in the database, if the table name is not present in the database, with a query call existence check.
\n**Returns the rowcount for the query, should be `0`.**
\n```python\njdb.create_table_if_false_check(\"table_name\", {\"jd\":[\"VARCHAR(128)\", \"PRIMARY KEY\"], \"column_name\":[\"DATATYPE\", \"DEFAULT VALUE\"]})\n```\n```python\n# with auto primary key insertion\njdb.create_table_if_false_check(\"table_name\", {\"column_name\":[\"DATATYPE\", \"DEFAULT VALUE\"], \"column2_name\":[\"DATATYPE\", \"DEFAULT VALUE\"]})\n```\n> The jdatabase package automatically adds a jd column as the primary key column (if a primary key column is not included).
\n\n> The recommend DEFAULT VALUE is `NOT NULL`.
\n\nData Methods:\n===\n\nget_one(name, [fields], (where, [parms]), (order, parms))\n---\nGets one row of data from the table in the connected database, named name.
\n**Returns the row of data.**
\n```python\nrow = jdb.get_one(\"table_name\", [\"field1\", \"field2\"])\n```\n```python\n# hard-coded condition\nrow = jdb.get_one(\"table_name\", where=(\"jd=a1\"))\n```\n```python\n# condition\nrow = jdb.get_one(\"table_name\", where=(\"jd=%s\", [\"jd_val\"]))\n```\n```python\n# extended condition\nrow = jdb.get_one(\"table_name\", where=(\"jd=%s and column1=%s\", [\"jd_val\", \"column1_val\"]))\n```\n```python\n# ordered by DESC\nrow = jdb.get_one(\"table_name\", order=(\"field\", \"DESC\"))\n```\n> Only the name value is required for get_one().
\n##### output:\n```\n(\"jd\", \"col1val\", \"col2val\", ...)\n```\n\nget_all(name, [fields], (where, [parms]), (order, parms))\n---\nGets all of the data from the table in the connected database, named name.
\n**Returns the data.**
\n```python\nrow = jdb.get_all(\"table_name\", [\"field1\", \"field2\"])\n```\n```python\n# hard-coded condition\nrow = jdb.get_all(\"table_name\", where=(\"jd=a1\"))\n```\n```python\n# condition\nrow = jdb.get_all(\"table_name\", where=(\"jd=%s\", [\"jd_val\"]))\n```\n```python\n# extended condition\nrow = jdb.get_all(\"table_name\", where=(\"jd=%s and column1=%s\", [\"jd_val\", \"column1_val\"]))\n```\n```python\n# ordered by DESC\nrow = jdb.get_all(\"table_name\", order=(\"field\", \"DESC\"))\n```\n> Only the name value is required for get_all().
\n##### output:\n```\n((\"jd\", \"col1val\", \"col2val\", ...),\n (\"jd\", \"col1val\", \"col2val\", ...), \n ...)\n```\n\ninsert(name, {data})\n---\nInserts a row of data into the table, named name, in the connected database.
\n**Returns the rowcount for query.**
\n```python\njdb.insert(\"table_name\", {\"column1name\": val, \"column2name\": xval})\n```\n> `vals` should be the same type as the column in the table.
\n\ninsert_batch(name, [{data1}, {data2}])\n---\nInserts a batch of data into the table, named name, in the connected database.
\n**Returns rowcount for query.**
\n```python\njdb.insert(\"table_name\", [{\"column1name\": val, \"column2name\": xval}, {\"column1name\": val2, \"column2name\": xval2}])\n```\n> `vals` should be the same type as the column in the table.
\n\nupdate(name, {data}, (where))\n---\nUpdates data in the table, named name, in the connected database.
\n**Returns rowcount for query.**
\n```python\njdb.update(\"table_name\", {\"column1name\": val, \"column2name\": xval}, where=(\"column1name=%s\", [\"row_val\"]))\n```\n> `vals` should be the same type as the column in the table.
\n\ninsert_or_update(name, {data}, key)\n---\nInsert data into or updates the data in the table, named name, in the connected database using a column, key, as a key for the comparision check between the parameter data and the data in the table.
\n**Returns rowcount for query.**
\n```python\njdb.insert_or_update(\"table_name\", {\"column1name\": val, \"column2name\": xval}, \"column1name\")\n```\n> `vals` should be the same type as the column in the table.
\n\ndelete(name, (where))\n---\nDelete row(s) in the table, named name, in the connected database, based on where condition.
\n**Returns rowcount for query.**
\n```python\n# delete entire table\njdb.delete(\"table_name\")\n```\n```python\n# delete with where condition\njdb.delete(\"table_name\", where=(\"jd=%s\", [\"val\"]))\n```\n\nlast_id()\n---\nGets the last insert id.
\n**Returns the last insert id.**
\n```python\njdb.last_id()\n```\n\nlast_query()\n---\nGets the last executed query.
\n**Returns the last executed query.**
\n```python\njdb.last_query()\n```\n\n\nClass Methods:\n===\n\nconnect()\n---\nMethod to establish a connection to the database. Automatically run on instantiation.
\n**Returns the database type of either `MySQL` or `PostgreSQL` in the form of a str.**
\n```python\njdb.connect()\n```\n\nis_open()\n---\nMethod to check if the connection object's connection to the database is open.
\n**Returns `True` if the connection is open, `False` if not.**
\n```python\njdb.is_open()\n```\n\nis_connected()\n---\nMethod to check if the database is open and if not if there is a connection error.
\n**Returns `True` if the connection is open, or if it was reestablished, or the connection error.**
\n```python\njdb.is_connected()\n```\n\nquery(sql, [parms])\n---\nMethod to execute a raw SQL query, with parms replacing `%s`s in the sql.
\n**Returns the cursor object.**
\n```python\njdb.query(\"SELECT * FROM table_name WHERE %s=%s;\", ['col1','select_me'])\n```\n> parms are NOT required.
\n\n> parms are required for any variable use, f\"\" strings DO NOT work.
\n\ncommit()\n---\nMethod to commit all current pending changes to the database. This method is only needed when autocommit is set to `False` in instantiation.
\n```python\njdb.commit()\n```\n\nclose()\n---\nMethod to close the connection to the database.
\n```python\njdb.close()\n```\n\nreconnect()\n--- \nMethod to close the connection to the database, if it is open, and then reopen the connection.
\n```python\njdb.reconnect()\n```\n\n`__str__`\n---\n**Returns the name of the database that the jdatabase object is connected to.**
\n```python\nstr(jdb)\n```\n##### output:\n```\n\"database_name\"\n```\n\nFootnote:\n===\nThis package was inspired by my need for an easier way to interact with databases in Python, and the [simplemysql](https://github.com/knadh/simplemysql \"simplemysql\") package.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/JoshWidrick/jdb", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "jdatabase", "package_url": "https://pypi.org/project/jdatabase/", "platform": "", "project_url": "https://pypi.org/project/jdatabase/", "project_urls": { "Homepage": "https://github.com/JoshWidrick/jdb" }, "release_url": "https://pypi.org/project/jdatabase/1.2.0a4/", "requires_dist": null, "requires_python": "", "summary": "jdatabase Python package. Designed for ease of database control and interaction within Python. The jdatabase package supports MySQL and PostgreSQL database systems.", "version": "1.2.0a4" }, "last_serial": 4920271, "releases": { "1.1.1a1": [ { "comment_text": "", "digests": { "md5": "b38323c94c1a74e06d5b78b02582f11b", "sha256": "3081b4cebf85a30ee246ed7644afe46f73dd82ea1cf0a295e80ab00d45047ba4" }, "downloads": -1, "filename": "jdatabase-1.1.1a1.tar.gz", "has_sig": false, "md5_digest": "b38323c94c1a74e06d5b78b02582f11b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7090, "upload_time": "2018-10-10T19:47:06", "url": "https://files.pythonhosted.org/packages/8e/96/488ef0d212c8024d95d0912b3288458b949dfcc52b6ebfa527da3a473ea5/jdatabase-1.1.1a1.tar.gz" } ], "1.1.1a3": [ { "comment_text": "", "digests": { "md5": "1d4aef4549f8786e36e8eae91913fa41", "sha256": "7230f2d36311e2158d088e3db3689118d62e79e9b6fd1fd8a4955fc9052895cf" }, "downloads": -1, "filename": "jdatabase-1.1.1a3.tar.gz", "has_sig": false, "md5_digest": "1d4aef4549f8786e36e8eae91913fa41", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7121, "upload_time": "2018-10-11T19:05:38", "url": "https://files.pythonhosted.org/packages/99/22/ecb2c9ad67d27823567b3ce252809bbc450b0f35f9f3c36f4d435996d108/jdatabase-1.1.1a3.tar.gz" } ], "1.2.0a1": [ { "comment_text": "", "digests": { "md5": "c26205c1d0ee098585c98f160416d292", "sha256": "b9d80796e12eea75a4ce287a395dfbe86665f9a7850d14dfbfbcd597fe4e65f0" }, "downloads": -1, "filename": "jdatabase-1.2.0a1.tar.gz", "has_sig": false, "md5_digest": "c26205c1d0ee098585c98f160416d292", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9151, "upload_time": "2019-03-06T19:48:21", "url": "https://files.pythonhosted.org/packages/ca/5e/92446b6508dcafec639be4e7b29a8e3e97aeb7509808b5c2676b485cf9ff/jdatabase-1.2.0a1.tar.gz" } ], "1.2.0a2": [ { "comment_text": "", "digests": { "md5": "21cc81f2a788f2405d011cc41eea086d", "sha256": "6ba00a579f2134a8c3e85b3f5f6a147f799e7b15a8d57db3e9cb283d4d6164d7" }, "downloads": -1, "filename": "jdatabase-1.2.0a2.tar.gz", "has_sig": false, "md5_digest": "21cc81f2a788f2405d011cc41eea086d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9149, "upload_time": "2019-03-06T19:54:08", "url": "https://files.pythonhosted.org/packages/e2/97/46b3fa963c1f300ceda4758ffa98f4379807327ad17c1943ec9b6f134387/jdatabase-1.2.0a2.tar.gz" } ], "1.2.0a3": [ { "comment_text": "", "digests": { "md5": "59b4ba359b0aa85e672ab138b13350b7", "sha256": "67bacfab86a74d76d98bcfc1a6fb6b2188cb17de9c8121c1513d357733e37fd7" }, "downloads": -1, "filename": "jdatabase-1.2.0a3.tar.gz", "has_sig": false, "md5_digest": "59b4ba359b0aa85e672ab138b13350b7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9143, "upload_time": "2019-03-06T19:56:14", "url": "https://files.pythonhosted.org/packages/38/65/2e2f3658c051f4fcbf6d8ab5b06cf0891c21a3df72f92f89c66a7760bc0d/jdatabase-1.2.0a3.tar.gz" } ], "1.2.0a4": [ { "comment_text": "", "digests": { "md5": "2b75a67b94394925222ff705205544bd", "sha256": "42f67accaa325cb1f1a5ee82a80faf9362cd3c004956837ea162b268df7abb5f" }, "downloads": -1, "filename": "jdatabase-1.2.0a4.tar.gz", "has_sig": false, "md5_digest": "2b75a67b94394925222ff705205544bd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9373, "upload_time": "2019-03-10T03:03:54", "url": "https://files.pythonhosted.org/packages/6d/b7/50a53da29fd253859d77209246f1361537093d8d385e455798290ff0f634/jdatabase-1.2.0a4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "2b75a67b94394925222ff705205544bd", "sha256": "42f67accaa325cb1f1a5ee82a80faf9362cd3c004956837ea162b268df7abb5f" }, "downloads": -1, "filename": "jdatabase-1.2.0a4.tar.gz", "has_sig": false, "md5_digest": "2b75a67b94394925222ff705205544bd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9373, "upload_time": "2019-03-10T03:03:54", "url": "https://files.pythonhosted.org/packages/6d/b7/50a53da29fd253859d77209246f1361537093d8d385e455798290ff0f634/jdatabase-1.2.0a4.tar.gz" } ] }