Skip to content

Commit bc05495

Browse files
committed
Updated README with usage and User API outline
1 parent 9de02e8 commit bc05495

File tree

1 file changed

+69
-18
lines changed

1 file changed

+69
-18
lines changed

README.md

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,46 +18,97 @@ pip install mysql-toolkit
1818

1919
MySQL-tookit aims to provide an easy to use MySQL dependency that allows developers to integrate MySQL database's with their Python applications.
2020

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.
2222

2323
```python
2424
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
42+
sql.update('anothertable', ['column1', 'column2'], ['value1', 2], ('id', 20421)
43+
44+
# 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
2549
```
2650

51+
## User API
2752
The MySQL class's methods are broken down into three categories and inherited via sub-modules.
2853

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 is not (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.
3093

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
4094

4195
## Built With
4296

4397
* [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
4699
* [tqdm](https://github.com/tqdm/tqdm) - A fast, extensible progress bar for Python
47100

48101
## Contributing
49102

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.
53104

54105
## Versioning
55106

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).
57108

58109
## Authors
59110

60-
* **Stephen Neal** - *Initial work* - [databasetools](https://github.com/mrstephenneal/mysql-toolkit)
111+
* **Stephen Neal** - *Initial work* - [mysql-toolkit](https://github.com/mrstephenneal/mysql-toolkit)
61112

62113

63114
## License

0 commit comments

Comments
 (0)