mysqldbutils


Namemysqldbutils JSON
Version 0.5 PyPI version JSON
download
home_pagehttps://github.com/technicalheist/pg-db-helpers.git
Summary
upload_time2023-12-01 14:58:03
maintainer
docs_urlNone
authorTechnical Heist
requires_python
licenseMIT
keywords mysql database crud utility
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            MySQL Database Utility Functions
=====================================

A set of Python functions to interact with MySQL databases. These
functions cover various database operations, including table
manipulation, data insertion, selection, update, and deletion.

Function Definitions
--------------------
from mysqldbutils import get_database_url, list_tables 

``get_database_url(host, port, database_name, username, password)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Returns a database_url which needs to pass for all the further functions

``list_tables(database_url)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Returns a list of tables in the specified MySQL database.

``create_table(database_url, table_name, columns)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Creates a new table in the database with the given name and columns.

``insert(database_url, table_name, data)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Inserts a single row of data into the specified table.

``insert_many(database_url, table_name, data_list)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Inserts multiple rows of data into the specified table.

``select_all(database_url, table_name)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Selects all rows from the specified table.

``select_with_pagination(database_url, table_name, from_index, to_index)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Selects a range of rows from the specified table with pagination.

``select_by_column(database_url, table_name, column_name, column_value)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Selects rows from the specified table where a specific column matches a
given value.

``select(database_url, table_name, where_dict)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Selects rows from the specified table based on the provided conditions.

``update(database_url, table_name, update_dict, where_dict)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Updates rows in the specified table based on the provided conditions
with new values.

``delete(database_url, table_name, where_dict)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Deletes rows from the specified table based on the provided conditions.

``truncate(database_url, table_name)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Truncates (removes all rows from) the specified table.

``delete_table(database_url, table_name)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Deletes the specified table from the database.

``sql_query(database_url, raw_sql_query)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Executes a raw SQL query on the specified database and returns the
result.

Example Usage
-------------

Below are examples illustrating the usage of some functions. Note that
you need to replace the placeholder values with your actual database
details.

\```python # Example usage of get_database_url database_url =
get_database_url(“localhost”, “5432”, “test”, “root”, “password”)

Example Usage of list_tables
============================

list_of_tables = list_tables(database_url) print(“List of Tables:”,
list_of_tables)

Example Usage of create_table
=============================

create_table(database_url, “new_table”, [“column1 INT”, “column2
VARCHAR(50)”])

Example Usage of insert
=======================

insert(database_url, “existing_table”, {“column1”: 123, “column2”:
“example_data”})

Example Usage of insert_many
============================

data_to_insert_many = [ {“column1”: 456, “column2”: “more_data”},
{“column1”: 789, “column2”: “additional_data”}]
insert_many(database_url, “existing_table”, data_to_insert_many)

Example Usage of select_all
===========================

all_rows = select_all(database_url, “existing_table”) print(“All Rows:”,
all_rows)

Example Usage of select_with_pagination
=======================================

selected_rows = select_with_pagination(database_url, “existing_table”,
1, 5) print(“Selected Rows:”, selected_rows)

Example Usage of select_by_column
=================================

selected_rows_by_column = select_by_column(database_url,
“existing_table”, “column1”, 456) print(“Selected Rows by Column:”,
selected_rows_by_column)

Example Usage of select
=======================

conditions = {“column1”: 123} selected_rows_with_conditions =
select(database_url, “existing_table”, conditions) print(“Selected Rows
with Conditions:”, selected_rows_with_conditions)

Example Usage of update
=======================

update_conditions = {“column1”: 123} update_values = {“column2”:
“updated_data”} update(database_url, “existing_table”, update_values,
update_conditions)

Example Usage of delete
=======================

delete_conditions = {“column1”: 123} delete(database_url,
“existing_table”, delete_conditions)

Example Usage of truncate
=========================

truncate(database_url, “existing_table”)

Example Usage of delete_table
=============================

delete_table(database_url, “existing_table”)

Example Usage of sql_query
==========================

raw_sql_query = “SELECT \* FROM example_table WHERE age > 25” result =
sql_query(database_url, raw_sql_query) print(result)


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/technicalheist/pg-db-helpers.git",
    "name": "mysqldbutils",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "MySQL,database,CRUD,utility",
    "author": "Technical Heist",
    "author_email": "contact@technicalheist.com",
    "download_url": "https://files.pythonhosted.org/packages/e4/09/730a0098631d7cd1263351a9e9d782de9b8c60360d81d1057be14fe4e80a/mysqldbutils-0.5.tar.gz",
    "platform": null,
    "description": "MySQL Database Utility Functions\n=====================================\n\nA set of Python functions to interact with MySQL databases. These\nfunctions cover various database operations, including table\nmanipulation, data insertion, selection, update, and deletion.\n\nFunction Definitions\n--------------------\nfrom mysqldbutils import get_database_url, list_tables \n\n``get_database_url(host, port, database_name, username, password)``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nReturns a database_url which needs to pass for all the further functions\n\n``list_tables(database_url)``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nReturns a list of tables in the specified MySQL database.\n\n``create_table(database_url, table_name, columns)``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nCreates a new table in the database with the given name and columns.\n\n``insert(database_url, table_name, data)``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nInserts a single row of data into the specified table.\n\n``insert_many(database_url, table_name, data_list)``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nInserts multiple rows of data into the specified table.\n\n``select_all(database_url, table_name)``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nSelects all rows from the specified table.\n\n``select_with_pagination(database_url, table_name, from_index, to_index)``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nSelects a range of rows from the specified table with pagination.\n\n``select_by_column(database_url, table_name, column_name, column_value)``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nSelects rows from the specified table where a specific column matches a\ngiven value.\n\n``select(database_url, table_name, where_dict)``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nSelects rows from the specified table based on the provided conditions.\n\n``update(database_url, table_name, update_dict, where_dict)``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nUpdates rows in the specified table based on the provided conditions\nwith new values.\n\n``delete(database_url, table_name, where_dict)``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nDeletes rows from the specified table based on the provided conditions.\n\n``truncate(database_url, table_name)``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nTruncates (removes all rows from) the specified table.\n\n``delete_table(database_url, table_name)``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nDeletes the specified table from the database.\n\n``sql_query(database_url, raw_sql_query)``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nExecutes a raw SQL query on the specified database and returns the\nresult.\n\nExample Usage\n-------------\n\nBelow are examples illustrating the usage of some functions. Note that\nyou need to replace the placeholder values with your actual database\ndetails.\n\n\\```python # Example usage of get_database_url database_url =\nget_database_url(\u201clocalhost\u201d, \u201c5432\u201d, \u201ctest\u201d, \u201croot\u201d, \u201cpassword\u201d)\n\nExample Usage of list_tables\n============================\n\nlist_of_tables = list_tables(database_url) print(\u201cList of Tables:\u201d,\nlist_of_tables)\n\nExample Usage of create_table\n=============================\n\ncreate_table(database_url, \u201cnew_table\u201d, [\u201ccolumn1 INT\u201d, \u201ccolumn2\nVARCHAR(50)\u201d])\n\nExample Usage of insert\n=======================\n\ninsert(database_url, \u201cexisting_table\u201d, {\u201ccolumn1\u201d: 123, \u201ccolumn2\u201d:\n\u201cexample_data\u201d})\n\nExample Usage of insert_many\n============================\n\ndata_to_insert_many = [ {\u201ccolumn1\u201d: 456, \u201ccolumn2\u201d: \u201cmore_data\u201d},\n{\u201ccolumn1\u201d: 789, \u201ccolumn2\u201d: \u201cadditional_data\u201d}]\ninsert_many(database_url, \u201cexisting_table\u201d, data_to_insert_many)\n\nExample Usage of select_all\n===========================\n\nall_rows = select_all(database_url, \u201cexisting_table\u201d) print(\u201cAll Rows:\u201d,\nall_rows)\n\nExample Usage of select_with_pagination\n=======================================\n\nselected_rows = select_with_pagination(database_url, \u201cexisting_table\u201d,\n1, 5) print(\u201cSelected Rows:\u201d, selected_rows)\n\nExample Usage of select_by_column\n=================================\n\nselected_rows_by_column = select_by_column(database_url,\n\u201cexisting_table\u201d, \u201ccolumn1\u201d, 456) print(\u201cSelected Rows by Column:\u201d,\nselected_rows_by_column)\n\nExample Usage of select\n=======================\n\nconditions = {\u201ccolumn1\u201d: 123} selected_rows_with_conditions =\nselect(database_url, \u201cexisting_table\u201d, conditions) print(\u201cSelected Rows\nwith Conditions:\u201d, selected_rows_with_conditions)\n\nExample Usage of update\n=======================\n\nupdate_conditions = {\u201ccolumn1\u201d: 123} update_values = {\u201ccolumn2\u201d:\n\u201cupdated_data\u201d} update(database_url, \u201cexisting_table\u201d, update_values,\nupdate_conditions)\n\nExample Usage of delete\n=======================\n\ndelete_conditions = {\u201ccolumn1\u201d: 123} delete(database_url,\n\u201cexisting_table\u201d, delete_conditions)\n\nExample Usage of truncate\n=========================\n\ntruncate(database_url, \u201cexisting_table\u201d)\n\nExample Usage of delete_table\n=============================\n\ndelete_table(database_url, \u201cexisting_table\u201d)\n\nExample Usage of sql_query\n==========================\n\nraw_sql_query = \u201cSELECT \\* FROM example_table WHERE age > 25\u201d result =\nsql_query(database_url, raw_sql_query) print(result)\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "",
    "version": "0.5",
    "project_urls": {
        "Homepage": "https://github.com/technicalheist/pg-db-helpers.git"
    },
    "split_keywords": [
        "mysql",
        "database",
        "crud",
        "utility"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f91369826504fbda1fe7b226229f7d9d6d077cf53172812897c791f4b310d119",
                "md5": "50360381e75ac85030de1e1517edab9f",
                "sha256": "d9749999b0d9fa624a78fe979362feea8c779b81591e650b8bf4b1e76a50af87"
            },
            "downloads": -1,
            "filename": "mysqldbutils-0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "50360381e75ac85030de1e1517edab9f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4514,
            "upload_time": "2023-12-01T14:57:58",
            "upload_time_iso_8601": "2023-12-01T14:57:58.854411Z",
            "url": "https://files.pythonhosted.org/packages/f9/13/69826504fbda1fe7b226229f7d9d6d077cf53172812897c791f4b310d119/mysqldbutils-0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e409730a0098631d7cd1263351a9e9d782de9b8c60360d81d1057be14fe4e80a",
                "md5": "4d42f5da01afb26aacec2d0bfb36b01e",
                "sha256": "a7cc334e4d4910c7469b45e6cd74ea2701c7b6279091a83600f252d3641ca97d"
            },
            "downloads": -1,
            "filename": "mysqldbutils-0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "4d42f5da01afb26aacec2d0bfb36b01e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4114,
            "upload_time": "2023-12-01T14:58:03",
            "upload_time_iso_8601": "2023-12-01T14:58:03.710920Z",
            "url": "https://files.pythonhosted.org/packages/e4/09/730a0098631d7cd1263351a9e9d782de9b8c60360d81d1057be14fe4e80a/mysqldbutils-0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-01 14:58:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "technicalheist",
    "github_project": "pg-db-helpers",
    "github_not_found": true,
    "lcname": "mysqldbutils"
}
        
Elapsed time: 0.14179s