You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+69-18Lines changed: 69 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,46 +18,97 @@ pip install mysql-toolkit
18
18
19
19
MySQL-tookit aims to provide an easy to use MySQL dependency that allows developers to integrate MySQL database's with their Python applications.
20
20
21
-
The entire MySQL-toolkit module can be utilized through a single import.
21
+
The entire MySQL-toolkit module can be utilized through a single import. To initialize a MySQL instance, simply provide a dictionary of MySQL database connection parameters with your call to MySQL within a context manager. Wrap all method and property calls with a context manager in order to automate connecting a disconnecting to a database.
22
22
23
23
```python
24
24
from mysql.toolkit import MySQL
25
+
26
+
# Database connection parameters
27
+
config = {
28
+
"database": "xxxnameofyourdatabasexxx",
29
+
"host": "xxxhosturlxxx",
30
+
"password": "xxxyourpasswordxxx",
31
+
"port": xxxhostportxxx,
32
+
"raise_on_warnings": true,
33
+
"user": "xxxyourusernamexxx"
34
+
}
35
+
36
+
# Establish a connection and execute queries
37
+
with MySQL(config) as sql:
38
+
# Select all rows from 'tablename'
39
+
results = sql.select_all('tablename')
40
+
41
+
# Update the row in 'anothertable' where the column 'id' equals 20421
# Retrieve a dictionary containing table, row_count key/values for every table in the database
45
+
counts= sql.count_rows_all()
46
+
47
+
# Query will fail and raise an error because the database connection is only maintained inside with context
48
+
tables= sql.tables() # Retrieve all tables in the database
25
49
```
26
50
51
+
## User API
27
52
The MySQL class's methods are broken down into three categories and inherited via sub-modules.
28
53
29
-
**core**
54
+
#### core
55
+
Method's that allow for programatic execution of basic SQL queries.
56
+
57
+
| Method | Description |
58
+
|---|---|
59
+
select | Query every row and only certain columns from a table
60
+
select_all | Query all rows and columns from a table
61
+
select\_all_join (coming soon) | Left join all rows and columns from two tables where a common value is shared
62
+
select_where | Query certain columns from a table where a particular value is found
63
+
insert | Insert a single row into a table
64
+
insert_many | Insert multiple rows into a table
65
+
update | Update the values of a particular row where a value is met
66
+
truncate | Empty a table by deleting all of its rows
67
+
drop | Drop a table from a database
68
+
69
+
#### results
70
+
Properties and methods that return metadata about a MySQL table(s).
71
+
72
+
| Method | Description |
73
+
|---|---|
74
+
tables | Retrieve a list of tables in the connected database
75
+
databases | Retrieve a list of databases that are accessible under the current connection
76
+
get\_primary_key | Retrieve the column which is the primary key for a table
77
+
get\_primary_key\_vals | Retrieve a list of primary key values in a table
78
+
get_schema | Retrieve the database schema for a particular table
79
+
count_rows | Get the number of rows in a particular table
80
+
count_rows_all | Get the number of rows for every table in the database
81
+
82
+
#### advanced
83
+
Methods provide functionality that isnot (easily) possible with standard MySQL queries
84
+
85
+
| Method | Description |
86
+
|---|---|
87
+
create_table (coming soon) | Generate and execute a create table query by parsing a 2D dataset
88
+
drop\_empty_tables | Drop all empty tables in a database
89
+
**insert_uniques**| Insert multiple rows into a table that do not already exist
90
+
update_many | Update the values of several rows
91
+
truncate_database | Drop all tables in a database
92
+
execute_script | Execute a sql file one command at a time.
30
93
31
-
* select
32
-
* select_all
33
-
* select_all_join (coming soon)
34
-
* select_where
35
-
* insert
36
-
* insert_many
37
-
* update
38
-
* truncate
39
-
* drop
40
94
41
95
## Built With
42
96
43
97
* [differentiate](https://github.com/mrstephenneal/differentiate) - Compare multiple data sets and retrieve the unique, non-repeated elements.
44
-
*[mysql-connector](https://dev.mysql.com/doc/connector-python/en/) - Self-container driver for communication with
45
-
MySQL servers
98
+
* [mysql-connector](https://dev.mysql.com/doc/connector-python/en/) - Self-container driver for communication with MySQL servers
46
99
* [tqdm](https://github.com/tqdm/tqdm) - A fast, extensible progress bar for Python
47
100
48
101
## Contributing
49
102
50
-
Please read [CONTRIBUTING.md](https://github.com/mrstephenneal/mysql-toolkit/contributing.md) for details on our
51
-
code of
52
-
conduct, and the process for submitting pull requests to us.
103
+
Please read [CONTRIBUTING.md](https://github.com/mrstephenneal/mysql-toolkit/contributing.md) for details on our code of conduct, and the process for submitting pull requests to us.
53
104
54
105
## Versioning
55
106
56
-
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/mrstephenneal/databasetools).
107
+
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/mrstephenneal/mysql-toolkit).
0 commit comments