1
1
import os
2
2
import shutil
3
+ from colorama import Fore
3
4
import errors
4
5
5
6
6
7
def documentation ():
7
- pass
8
+ return Fore .GREEN + f'''
9
+ Current Functionalities:
10
+
11
+ - Creating DataBase
12
+ - Using/Changing DataBase
13
+ - Creating Tables and Files
14
+ - Writing in Tables and Files
15
+ - Checking the content of Tables and Files
16
+ - Deleting DataBases, Tables and Files
17
+ - Saves all the code in File.
18
+
19
+ { Fore .MAGENTA + "All commands can be in upper or lower case!" }
20
+
21
+ { Fore .GREEN + "1.How to create DataBase:" }
22
+ - At first, you'll be asked to use or create database,
23
+ - if you choose to create database, it'll just ask you for the name.
24
+ - Otherwise, if you want to create database while working,
25
+ - Use the current command: CREATE DATABASE DataBaseName
26
+
27
+ 2.How to use/change database:
28
+ - At first, you'll be asked to use or create database,
29
+ - if you choose to use database, it'll just ask you for the name.
30
+ - Otherwise, if you want to change the database you're working with,
31
+ - Use the current command: USE DATABASE DataBaseName
32
+
33
+ 3.How to create a table and save information in it:
34
+ - To create a table, you need to use the main keywords "CREATE TABLE",
35
+ - And then, the name of the table, containing information about the storage,
36
+ - Example: TableName(id: int, name: str)
37
+ - Console command: CREATE TABLE TableName(id: int, name: str, age: float, more...)
38
+ - To write in table, you can see this Example:
39
+
40
+ { Fore .CYAN + "ADD TableName VALUES (" }
41
+ (id, name, age, more...)
42
+ (id, name, age)
43
+ );
44
+
45
+ { Fore .GREEN + "4.How to create file and write in it:" }
46
+ - To create a file, use the following command: CREATE FILE FileName
47
+ - To write in file, you need to start with the keywords "WRITE IN FileName:",
48
+ - And then, write whatever you want on every new line.
49
+ - To stop writing, you need to use ";;;" at the end
50
+ "WARNING": """The ;;; get also saved in the txt file, so if you don't want them attached to your text,
51
+ you might write them on new line!
52
+ """
53
+ - Write Example:
54
+
55
+
56
+ { Fore .CYAN + "WRITE IN FileName:" }
57
+ Something isn't right.
58
+ Some Messages!
59
+ content, content, content,
60
+ content, content,
61
+ content,
62
+ content,
63
+ content;;;
64
+
65
+ { Fore .GREEN + "5.How to see the content of my Tables and Files:" }
66
+ - Use this command for Tables: GET ALL TableName
67
+ - Use this command for Files: GET FILE FileName
68
+
69
+ 6.How to delete DataBases, Tables and Files:
70
+ - Delete DataBase/s:
71
+
72
+ { Fore .MAGENTA + "One DataBase:" }
73
+ FIRST WAY: DROP DB DataBaseName
74
+ SECOND WAY: DROP DATABASE DataBaseName
75
+
76
+ More Than One DataBases:
77
+ FIRST WAY: DROP DBS FirstDataBaseName SecondDataBaseName ThirdDataBaseName...
78
+ SECOND WAY: DROP DATABASES FirstDataBaseName SecondDataBaseName ThirdDataBaseName...
79
+
80
+ { Fore .GREEN + "- Delete Tables:" }
81
+
82
+ { Fore .MAGENTA + "One Table:" }
83
+ DROP TABLE TableName
84
+
85
+ More Than One Table:
86
+ DROP TABLES FirstTableName SecondTableName ThirdTableName...
87
+
88
+ { Fore .GREEN + "- Delete Files:" }
89
+
90
+ { Fore .MAGENTA + "One File:" }
91
+ DEL FILE FileName
92
+
93
+ More Than One File:
94
+ DEL FILES FirstFileName SecondFileName ThirdFileName...
95
+
96
+
97
+
98
+ { Fore .LIGHTGREEN_EX + "7.How to save the code?" }
99
+ - The code is saving by itself in the chosen at the beginning by you file, to change the file
100
+ you must stop the program and rerun it. The file can be found in the same directory "src/filename"
101
+
102
+
103
+ Submit issues and questions here: https://github.com/MitkoVtori/Python-ConsoleSQL/issues/new
104
+
105
+ '''
8
106
9
107
10
108
def create_database (database , * args ):
@@ -18,9 +116,9 @@ def create_database(database, *args):
18
116
os .mkdir (f"databases/{ database } " ), os .mkdir (f"databases/{ database } /files" ), os .mkdir (f"databases/{ database } /tables" )
19
117
20
118
except FileExistsError :
21
- return "Database already exists"
119
+ return Fore . WHITE + "Database already exists"
22
120
23
- return f"Database \" { database } \" was created"
121
+ return Fore . WHITE + f"Database \" { database } \" was created"
24
122
25
123
26
124
def use_database (database , * args ):
@@ -30,9 +128,9 @@ def use_database(database, *args):
30
128
'''
31
129
32
130
if os .path .exists (f"databases/{ database } /" ):
33
- return [f"Currently working with database \" { database } \" " , database ]
131
+ return [Fore . WHITE + f"Currently working with database \" { database } \" " , database ]
34
132
35
- raise errors .DataBaseNotFoundError (f"Database \" { database } \" not found!" )
133
+ raise errors .DataBaseNotFoundError (Fore . WHITE + f"Database \" { database } \" not found!" )
36
134
37
135
38
136
def create_table (database , table , values , * args ):
@@ -42,13 +140,13 @@ def create_table(database, table, values, *args):
42
140
'''
43
141
44
142
if os .path .exists (f"databases/{ database } /tables/{ table } .txt" ):
45
- return f"Table already exists!"
143
+ return Fore . WHITE + f"Table already exists!"
46
144
47
145
table = open (f"databases/{ database } /tables/{ table } .txt" , "a+" )
48
146
table .write (f"{ values } \n \n " )
49
147
table .close ()
50
148
51
- return f"Table \" { table } \" was created!"
149
+ return Fore . WHITE + f"Table \" { table } \" was created!"
52
150
53
151
54
152
def add_content_to_table (database , table , * content ):
@@ -96,7 +194,7 @@ def add_content_to_table(database, table, *content):
96
194
except Exception as e :
97
195
raise e
98
196
99
- return "Content added to table!"
197
+ return Fore . WHITE + "Content added to table!"
100
198
101
199
102
200
def create_file (database , file_name ):
@@ -106,12 +204,12 @@ def create_file(database, file_name):
106
204
'''
107
205
108
206
if os .path .exists (f"databases/{ database } /files/{ file_name } .txt" ):
109
- return "File already exists"
207
+ return Fore . WHITE + "File already exists"
110
208
111
209
file = open (f"databases/{ database } /files/{ file_name } .txt" , 'x' )
112
210
file .close ()
113
211
114
- return f"File \" { file_name } \" was created!"
212
+ return Fore . WHITE + f"File \" { file_name } \" was created!"
115
213
116
214
117
215
def write_in_file (database , file , * content ):
@@ -132,9 +230,9 @@ def write_in_file(database, file, *content):
132
230
for line in content :
133
231
f .write (f"{ line } \n " )
134
232
135
- return "Content added to file!"
233
+ return Fore . WHITE + "Content added to file!"
136
234
137
- return f"Database \" { database } \" or File \" { file } \" not found!"
235
+ return Fore . WHITE + f"Database \" { database } \" or File \" { file } \" not found!"
138
236
139
237
140
238
def check_table_content (database , table , * args ):
@@ -146,9 +244,9 @@ def check_table_content(database, table, *args):
146
244
if os .path .exists (f"databases/{ database } /tables/{ table } .txt" ):
147
245
file = open (f"databases/{ database } /tables/{ table } .txt" , "r" )
148
246
149
- return [line for line in file ][2 :]
247
+ return [Fore . WHITE + line for line in file ][2 :]
150
248
151
- print ("Table not found!" )
249
+ print (Fore . WHITE + "Table not found!" )
152
250
return []
153
251
154
252
@@ -161,7 +259,7 @@ def check_file_content(database, file_name, *border):
161
259
if os .path .exists (f"databases/{ database } /files/{ file_name } .txt" ):
162
260
file = open (f"databases/{ database } /files/{ file_name } .txt" , "r" )
163
261
164
- return [line for line in file ]
262
+ return [Fore . WHITE + line for line in file ]
165
263
166
264
print ("File not found!" )
167
265
return []
@@ -184,7 +282,7 @@ def drop_database(*databases):
184
282
if os .path .exists (f"databases/{ db } /" ):
185
283
shutil .rmtree (f"databases/{ db } /" )
186
284
187
- return "Database/s dropped!"
285
+ return Fore . WHITE + "Database/s dropped!"
188
286
189
287
190
288
def drop_table (database , * tables ):
@@ -202,15 +300,15 @@ def drop_table(database, *tables):
202
300
if os .path .exists (f"databases/{ database } /tables/{ table } .txt" ):
203
301
os .remove (f"databases/{ database } /tables/{ table } .txt" )
204
302
205
- return "Table/s dropped!"
303
+ return Fore . WHITE + "Table/s dropped!"
206
304
207
305
208
306
def delete_file (database , * files ):
209
307
'''
210
308
Console command
211
309
212
310
One File:
213
- DEL FILE TableName
311
+ DEL FILE FileName
214
312
215
313
More Than One File:
216
314
DEL FILES FirstFileName SecondFileName ThirdFileName...
@@ -220,7 +318,7 @@ def delete_file(database, *files):
220
318
if os .path .exists (f"databases/{ database } /files/{ file } .txt" ):
221
319
os .remove (f"databases/{ database } /files/{ file } .txt" )
222
320
223
- return "File/s deleted!"
321
+ return Fore . WHITE + "File/s deleted!"
224
322
225
323
226
324
def code_saver (user_input , code_file , new_line ):
@@ -234,23 +332,28 @@ def code_saver(user_input, code_file, new_line):
234
332
235
333
236
334
def run_program ():
335
+ see_documentation = input (Fore .WHITE + "Wanna see the documentation? 'yes' or 'no': " )
336
+
337
+ if see_documentation .lower () == "yes" :
338
+ print (documentation ())
339
+
237
340
while True :
238
- db = input ("create or use database: " )
341
+ db = input (Fore . WHITE + "create or use database: " )
239
342
240
343
if db == 'create' :
241
- create_db = input ("database name: " )
344
+ create_db = input (Fore . WHITE + "database name: " )
242
345
create_database (create_db )
243
346
d = use_database (create_db )
244
347
break
245
348
246
349
elif db == "use" :
247
- d = use_database (input ("database name: " ))[- 1 ]
350
+ d = use_database (input (Fore . WHITE + "database name: " ))[- 1 ]
248
351
break
249
352
250
353
database = d
251
354
252
355
while True :
253
- file = input ("Create or choose file where to save the code from your console experience:\n " )
356
+ file = input (Fore . WHITE + "Create or choose file where to save the code from your console experience:\n " )
254
357
255
358
if not os .path .exists (f"src/{ file } .txt" ):
256
359
f = open (f"src/{ file } .txt" , "x" )
@@ -264,15 +367,17 @@ def run_program():
264
367
while True :
265
368
266
369
operation_code = input ()
267
- operation = operation_code .lower ().split ()
268
-
269
- code_saver (operation_code , file , '\n ' )
270
370
271
371
if operation_code == "END" :
272
372
break
273
373
274
374
if operation_code == "docs" :
275
- print (documentation ().__doc__ ())
375
+ print (documentation ())
376
+ continue
377
+
378
+ operation = operation_code .lower ().split ()
379
+
380
+ code_saver (operation_code , file , '\n ' )
276
381
277
382
if len (operation ) >= 3 :
278
383
if operation [- 1 ]:
0 commit comments