easymysql


Nameeasymysql JSON
Version 0.1.9.2 PyPI version JSON
download
home_pagehttps://github.com/alvarodeleon/easymysql
SummaryEasy MySQL Manager
upload_time2024-12-29 23:48:06
maintainerNone
docs_urlNone
authorAlvaro De Leon
requires_pythonNone
licenseNone
keywords mysql sql query
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # EasyMySQL: A Library for Managing MySQL in Python

[Sitio Web del proyecto](https://www.alvarodeleon.net/easymysql-una-libreria-para-manejo-de-mysql-en-python/)

## Downloads
| **Total** | **Last Month** | **Last Week** |
|-----------|----------------|---------------|
| [![Downloads](https://static.pepy.tech/badge/easymysql)](https://pepy.tech/project/easymysql) | [![Downloads](https://static.pepy.tech/badge/easymysql/month)](https://pepy.tech/project/easymysql) | [![Downloads](https://static.pepy.tech/badge/easymysql/week)](https://pepy.tech/project/easymysql) |



## Installing EasyMySQL

```
pip install easymysql
```
If you encounter an error due to having an older version of Python, you can use:
```
pip3 install easymysql
```
## Connecting to the Database
```
#!/usr/bin/python

from easymysql.mysql import mysql

my = mysql('localhost','user_db','pass_db','db_name')
```

## Inserting Data
Inserting data is extremely easy; you only need to provide two parameters: the table name and an array with the data to insert:
```
my.insert('table_name',{
	'field_1':'value_1',
	'field_2':'value_2',
	'field_3':'value_3',
})
```
The array uses a Key-Value format where the key corresponds to the table field name, and the value is the value to be inserted.

## Updating Data
Updating data is similar to inserting, but this time you need to pass three parameters: the table name, an array with the data to update (Key-Value format), and a third parameter specifying the **WHERE** clause, either as a Key-Value array or a SQL string:
```
my.update('table_name',{
	'field_1':'value_1',
	'field_2':'value_2',
	'field_3':'value_3',
},{
	'id':300
})
```
The third parameter, if given as an array, will generate a standard SQL string concatenated with **AND**. For example:
```
my.update('table_name',{
	'field_1':'value_1'
},{
	'field_2':'value_3',
	'field_3': 'value_3'
})
```

This translates to:
```
UPDATE table_name SET field_1=value_1 WHERE field_2='value_2' AND field_3='value_3'
```
Alternatively, if the third parameter is a string:
```
my.update('table_name',{
	'field_1':'value_1',
	'field_2':'value_2',
	'field_3':'value_3',
},
	'field_2=value_2 OR field_3=value_3
)
```
This translates to:
```
UPDATE table_name SET field_1=value_1,field_2=value_2,field_3=value_3 WHERE field_2='value_2' OR field_3='value_3'
```
## Querying and Listing Data

The SELECT function works similarly to the previous cases. You provide the table name, an optional WHERE condition as an array or string, and optionally an ORDER clause as the third parameter.

To filter data:
```
lst = my.select('table_name', {'field_1': value_1})

lst = my.select('table_name', "field_1='value_1'")
```
If there's only one result:
```
[{'field_1': 'value_1', 'field_2': 'value_2','field_3':'value_3'}]
```
If there are multiple results:
```
[{'field_1': 'value_1', 'field_2': 'value_2','field_3':'value_3'},
{'field_1': 'value4', 'field_2': 'value_5','field_3':'value_6'},
{'field_1': 'value_7', 'field_2': 'value_8','field_3':'value_9'}]
```
You can also use standard SQL WHERE clauses with LIKE, OR, >, <, etc.:
```
lst = my.select('table_name', "field_1 LIKE '%value%')
```
## ORDER Clause

Technically, the **ORDER** clause can include any SQL statement that follows the **WHERE** clause:
```
lst = my.select('table_name', "field_1 LIKE '%value%',order='LIMIT 10')
lst = my.select('table_name', "field_1 LIKE '%value%',order='LIMIT 1,10')
lst = my.select('table_name', "field_1 LIKE '%value%',order='ORDER BY id DESC')
lst = my.select('table_name', "field_1 LIKE '%value%',order='ORDER BY id DESC LIMIT 5')
lst = my.select('table_name', "field_1 LIKE '%value%',order='ORDER BY id DESC LIMIT 1,10')
```
## Iterating Through Data

To iterate through the data, simply use a **for** loop:
```
lst = my.select('table_name')

for item in lst:
    print(item)

for item in lst:
    print(item['field_1'])
    print(item['field_2'])
    print(item['field_3'])
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/alvarodeleon/easymysql",
    "name": "easymysql",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "mysql, sql, query",
    "author": "Alvaro De Leon",
    "author_email": "deleon@adl.com.uy",
    "download_url": "https://files.pythonhosted.org/packages/61/de/e71b8891d1d46d5ec4912e1210063bdead15e98ea2720f86db3b90079251/easymysql-0.1.9.2.tar.gz",
    "platform": null,
    "description": "# EasyMySQL: A Library for Managing MySQL in Python\n\n[Sitio Web del proyecto](https://www.alvarodeleon.net/easymysql-una-libreria-para-manejo-de-mysql-en-python/)\n\n## Downloads\n| **Total** | **Last Month** | **Last Week** |\n|-----------|----------------|---------------|\n| [![Downloads](https://static.pepy.tech/badge/easymysql)](https://pepy.tech/project/easymysql) | [![Downloads](https://static.pepy.tech/badge/easymysql/month)](https://pepy.tech/project/easymysql) | [![Downloads](https://static.pepy.tech/badge/easymysql/week)](https://pepy.tech/project/easymysql) |\n\n\n\n## Installing EasyMySQL\n\n```\npip install easymysql\n```\nIf you encounter an error due to having an older version of Python, you can use:\n```\npip3 install easymysql\n```\n## Connecting to the Database\n```\n#!/usr/bin/python\n\nfrom easymysql.mysql import mysql\n\nmy = mysql('localhost','user_db','pass_db','db_name')\n```\n\n## Inserting Data\nInserting data is extremely easy; you only need to provide two parameters: the table name and an array with the data to insert:\n```\nmy.insert('table_name',{\n\t'field_1':'value_1',\n\t'field_2':'value_2',\n\t'field_3':'value_3',\n})\n```\nThe array uses a Key-Value format where the key corresponds to the table field name, and the value is the value to be inserted.\n\n## Updating Data\nUpdating data is similar to inserting, but this time you need to pass three parameters: the table name, an array with the data to update (Key-Value format), and a third parameter specifying the **WHERE** clause, either as a Key-Value array or a SQL string:\n```\nmy.update('table_name',{\n\t'field_1':'value_1',\n\t'field_2':'value_2',\n\t'field_3':'value_3',\n},{\n\t'id':300\n})\n```\nThe third parameter, if given as an array, will generate a standard SQL string concatenated with **AND**. For example:\n```\nmy.update('table_name',{\n\t'field_1':'value_1'\n},{\n\t'field_2':'value_3',\n\t'field_3': 'value_3'\n})\n```\n\nThis translates to:\n```\nUPDATE table_name SET field_1=value_1 WHERE field_2='value_2' AND field_3='value_3'\n```\nAlternatively, if the third parameter is a string:\n```\nmy.update('table_name',{\n\t'field_1':'value_1',\n\t'field_2':'value_2',\n\t'field_3':'value_3',\n},\n\t'field_2=value_2 OR field_3=value_3\n)\n```\nThis translates to:\n```\nUPDATE table_name SET field_1=value_1,field_2=value_2,field_3=value_3 WHERE field_2='value_2' OR field_3='value_3'\n```\n## Querying and Listing Data\n\nThe SELECT function works similarly to the previous cases. You provide the table name, an optional WHERE condition as an array or string, and optionally an ORDER clause as the third parameter.\n\nTo filter data:\n```\nlst = my.select('table_name', {'field_1': value_1})\n\nlst = my.select('table_name', \"field_1='value_1'\")\n```\nIf there's only one result:\n```\n[{'field_1': 'value_1', 'field_2': 'value_2','field_3':'value_3'}]\n```\nIf there are multiple results:\n```\n[{'field_1': 'value_1', 'field_2': 'value_2','field_3':'value_3'},\n{'field_1': 'value4', 'field_2': 'value_5','field_3':'value_6'},\n{'field_1': 'value_7', 'field_2': 'value_8','field_3':'value_9'}]\n```\nYou can also use standard SQL WHERE clauses with LIKE, OR, >, <, etc.:\n```\nlst = my.select('table_name', \"field_1 LIKE '%value%')\n```\n## ORDER Clause\n\nTechnically, the **ORDER** clause can include any SQL statement that follows the **WHERE** clause:\n```\nlst = my.select('table_name', \"field_1 LIKE '%value%',order='LIMIT 10')\nlst = my.select('table_name', \"field_1 LIKE '%value%',order='LIMIT 1,10')\nlst = my.select('table_name', \"field_1 LIKE '%value%',order='ORDER BY id DESC')\nlst = my.select('table_name', \"field_1 LIKE '%value%',order='ORDER BY id DESC LIMIT 5')\nlst = my.select('table_name', \"field_1 LIKE '%value%',order='ORDER BY id DESC LIMIT 1,10')\n```\n## Iterating Through Data\n\nTo iterate through the data, simply use a **for** loop:\n```\nlst = my.select('table_name')\n\nfor item in lst:\n    print(item)\n\nfor item in lst:\n    print(item['field_1'])\n    print(item['field_2'])\n    print(item['field_3'])\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Easy MySQL Manager",
    "version": "0.1.9.2",
    "project_urls": {
        "Download": "https://github.com/alvarodeleon/easymysql/tarball/0.1.9.2",
        "Homepage": "https://github.com/alvarodeleon/easymysql"
    },
    "split_keywords": [
        "mysql",
        " sql",
        " query"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ccc7512e7019de850b439de0486a542687ed918efa787ac61e458f92303db211",
                "md5": "84dab4ca1ad6c232873ea398343cf76a",
                "sha256": "c61002a7ba1e37f1d28f7d327bbf221d9e549f4f596800b88f4cf32ade637145"
            },
            "downloads": -1,
            "filename": "easymysql-0.1.9.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "84dab4ca1ad6c232873ea398343cf76a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4121,
            "upload_time": "2024-12-29T23:47:42",
            "upload_time_iso_8601": "2024-12-29T23:47:42.409138Z",
            "url": "https://files.pythonhosted.org/packages/cc/c7/512e7019de850b439de0486a542687ed918efa787ac61e458f92303db211/easymysql-0.1.9.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "61dee71b8891d1d46d5ec4912e1210063bdead15e98ea2720f86db3b90079251",
                "md5": "a8866e65406dfb20f8b0a8bcb2f8db7d",
                "sha256": "f1578cc2f02df29c840fbc0f31c0f628b6a3234d6f2869a059d05e71e956c808"
            },
            "downloads": -1,
            "filename": "easymysql-0.1.9.2.tar.gz",
            "has_sig": false,
            "md5_digest": "a8866e65406dfb20f8b0a8bcb2f8db7d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3816,
            "upload_time": "2024-12-29T23:48:06",
            "upload_time_iso_8601": "2024-12-29T23:48:06.737707Z",
            "url": "https://files.pythonhosted.org/packages/61/de/e71b8891d1d46d5ec4912e1210063bdead15e98ea2720f86db3b90079251/easymysql-0.1.9.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-29 23:48:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "alvarodeleon",
    "github_project": "easymysql",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "easymysql"
}
        
Elapsed time: 5.93165s