-
Notifications
You must be signed in to change notification settings - Fork 0
/
PKG-INFO
269 lines (193 loc) · 7.77 KB
/
PKG-INFO
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
Metadata-Version: 2.2
Name: lisql
Version: 2.2
Summary: Provides simple funtions to interact with MySQL databases and tables.
Home-page: https://github.com/li812/lisql
Author: Ali Ahammad
Author-email: aliahammad0812@outlook.com
Project-URL: Bug Tracker, https://github.com/li812/lisql/issues
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
# lisql
lisql is a Python package that provides a simple interface for interacting with MySQL databases. It includes functions for creating connections, creating and dropping databases and tables, inserting and selecting data, updating and deleting rows, and more.
# Make sure you have upgraded version of pip
Windows
```
py -m pip install --upgrade pip
```
Linux/MAC OS
```
python3 -m pip install --upgrade pip
```
# Make sure you mysql connector installed
Windows
```
py -m pip install mysql-connector-python
```
Linux/MAC OS
```
python3 -m pip install mysql-connector-python
```
## INSTALATION
Run the following to install `lisql`, using pip:
```
pip install lisql
```
## Functions
- `creacon()`: creates a connection to a MySQL server on the localhost with default credentials.
- `creacuscon(host, username, password)`: creates a custom connection to a MySQL server with the provided host, username, and password.
- `creadb(name)`: creates a new MySQL database with the given name if it does not already exist.
- `dropdb(name)`: drops the MySQL database with the given name if it exists.
- `condb(name)`: connects to the MySQL database with the given name if it exists.
- `cuscondb(host, username, password, dbname)`: connects to the custom MySQL database with the provided host, username, password, and dbname.
- `create_table(table_name, columns)`: creates a new table in the currently connected MySQL database with the given table name and columns.
- `drop_table(table_name)`: drops the table with the given table name in the currently connected MySQL database.
- `insert_data(table_name, values)`: inserts a row of data into the table with the given table name and values.
- `select_data(table_name, columns)`: retrieves the data from the table with the given table name and columns.
- `update_data(table_name, column_values, condition)`: updates the rows in the table with the given table name that meet the given condition with the new column values.
- `delete_data(table_name, condition)`: deletes the rows in the table with the given table name that meet the given condition.
- `close_con()`: closes the connection to the MySQL database if it is open.
- `show_databases()`: retrieves a list of all databases on the MySQL server.
- `show_tables()`: retrieves a list of all tables in the currently selected database.
- `execute_query(query, fetch=False)`: executes a SQL query string using a cursor object.
- `describe_table(table_name)`: retrieves information about the columns of a table.
- `about()`: to know about the auother.
## Usage
### Creating a default connection
To create a default connection to a MySQL server on the localhost with default credentials, use the creacon function:
```
import lisql
lisql.creacon()
```
### Creating a custom connection
To create a custom connection to a MySQL server with the provided host, username, and password, use the creacuscon function:
```
import lisql
lisql.creacuscon(host, username, password)
```
### Creating a database
To create a new MySQL database with the given name if it does not already exist, use the creadb function:
```
import lisql
lisql.creadb(name)
```
### Dropping a database
To drop the MySQL database with the given name if it exists, use the dropdb function:
```
import lisql
lisql.dropdb(name)
```
### Connecting to a database
To connect to the MySQL database with the given name if it exists, use the condb function:
```
import lisql
lisql.condb(database_name)
```
### Connecting to a custom database
To connect to the custom MySQL database with the provided host, username, password, and dbname, use the cuscondb function:
```
import lisql
lisql.cuscondb(host, username, password, dbname)
```
### Creating a table
To create a new table in the currently connected MySQL database with the given table name and columns, use the create_table function:
```
import lisql
columns = {
"column1": "VARCHAR(255)",
"column2": "INT",
"column3": "DATETIME"
}
lisql.create_table("my_table", columns)
```
### Dropping a table
To drop the table with the given table name in the currently connected MySQL database, use the drop_table function:
```
import lisql
lisql.drop_table("my_table")
```
### Inserting data
To insert a row of data into the table with the given table name and values, use the insert_data function:
```
import lisql
values = {
"column1": "value1",
"column2": 123,
"column3": "2022-03-08 12:00:00"
}
lisql.insert_data("my_table", values)
```
### Retrieving data
To retrieve the data from the table with the given table name and columns, use the select_data function:
```
import lisql
columns = ["column1", "column2", "column3"]
data = lisql.select_data("my_table", columns)
for row in data:
print(row)
```
### Updating data
To update the rows in the table with the given table name that meet the given condition with the new column values, use the update_data function:
```
import lisql
column_values = {
"column2": 456,
"column3": "2022-03-08 13:00:00"
}
condition = "column1 = 'value1'"
lisql.update_data("my_table", column_values, condition)
```
### Deleting Data
To delete rows from a table, you can use the delete_data function. It takes two arguments: the table_name and a condition that specifies which rows to delete.
```
import lisql
table_name = "employees"
condition = "salary < 50000"
lisql.delete_data(table_name, condition)
```
### Closing the Connection
When you're finished working with the database, you should close the connection using the close_con function. This will close the connection to the database. If you try to execute any functions that require a database connection after calling close_con, you will get an error.
```
import lisql
lisql.close_con()
```
### Getting a List of Databases and Tables
You can get a list of all the databases on the MySQL server using the show_databases function. This will return a list of database names.
```
import lisql
lisql.show_databases()
```
To get a list of all the tables in the currently selected database, you can use the show_tables function:
```
import lisql
lisql.show_tables()
```
This will return a list of table names.
### Executing SQL Queries
If you need to execute a SQL query that is not covered by the functions provided by lisql, you can use the execute_query function. It takes one argument: the SQL query string.
```
import lisql
lisql.execute_query(query)
```
By default, execute_query will not return any results. If you want to retrieve the results of the query, you can set the fetch argument to True:
```
im;ort lisql
lisql.execute_query(query, fetch=True)
```
This will return the results of the query as a list of tuples.
### Retrieving Table Information
You can get information about the columns in a table using the describe_table function. It takes one argument: the table_name.
```
import lisql
lisql.describe_table(table_name)
```
This will return a list of dictionaries, where each dictionary represents a column in the table. The keys of the dictionary are the column attributes (e.g. "Field", "Type", "Null", etc.) and the values are the corresponding values for each column.