11import os
22import shutil
3+ from colorama import Fore
34import errors
45
56
67def 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+ '''
8106
9107
10108def create_database (database , * args ):
@@ -18,9 +116,9 @@ def create_database(database, *args):
18116 os .mkdir (f"databases/{ database } " ), os .mkdir (f"databases/{ database } /files" ), os .mkdir (f"databases/{ database } /tables" )
19117
20118 except FileExistsError :
21- return "Database already exists"
119+ return Fore . WHITE + "Database already exists"
22120
23- return f"Database \" { database } \" was created"
121+ return Fore . WHITE + f"Database \" { database } \" was created"
24122
25123
26124def use_database (database , * args ):
@@ -30,9 +128,9 @@ def use_database(database, *args):
30128 '''
31129
32130 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 ]
34132
35- raise errors .DataBaseNotFoundError (f"Database \" { database } \" not found!" )
133+ raise errors .DataBaseNotFoundError (Fore . WHITE + f"Database \" { database } \" not found!" )
36134
37135
38136def create_table (database , table , values , * args ):
@@ -42,13 +140,13 @@ def create_table(database, table, values, *args):
42140 '''
43141
44142 if os .path .exists (f"databases/{ database } /tables/{ table } .txt" ):
45- return f"Table already exists!"
143+ return Fore . WHITE + f"Table already exists!"
46144
47145 table = open (f"databases/{ database } /tables/{ table } .txt" , "a+" )
48146 table .write (f"{ values } \n \n " )
49147 table .close ()
50148
51- return f"Table \" { table } \" was created!"
149+ return Fore . WHITE + f"Table \" { table } \" was created!"
52150
53151
54152def add_content_to_table (database , table , * content ):
@@ -96,7 +194,7 @@ def add_content_to_table(database, table, *content):
96194 except Exception as e :
97195 raise e
98196
99- return "Content added to table!"
197+ return Fore . WHITE + "Content added to table!"
100198
101199
102200def create_file (database , file_name ):
@@ -106,12 +204,12 @@ def create_file(database, file_name):
106204 '''
107205
108206 if os .path .exists (f"databases/{ database } /files/{ file_name } .txt" ):
109- return "File already exists"
207+ return Fore . WHITE + "File already exists"
110208
111209 file = open (f"databases/{ database } /files/{ file_name } .txt" , 'x' )
112210 file .close ()
113211
114- return f"File \" { file_name } \" was created!"
212+ return Fore . WHITE + f"File \" { file_name } \" was created!"
115213
116214
117215def write_in_file (database , file , * content ):
@@ -132,9 +230,9 @@ def write_in_file(database, file, *content):
132230 for line in content :
133231 f .write (f"{ line } \n " )
134232
135- return "Content added to file!"
233+ return Fore . WHITE + "Content added to file!"
136234
137- return f"Database \" { database } \" or File \" { file } \" not found!"
235+ return Fore . WHITE + f"Database \" { database } \" or File \" { file } \" not found!"
138236
139237
140238def check_table_content (database , table , * args ):
@@ -146,9 +244,9 @@ def check_table_content(database, table, *args):
146244 if os .path .exists (f"databases/{ database } /tables/{ table } .txt" ):
147245 file = open (f"databases/{ database } /tables/{ table } .txt" , "r" )
148246
149- return [line for line in file ][2 :]
247+ return [Fore . WHITE + line for line in file ][2 :]
150248
151- print ("Table not found!" )
249+ print (Fore . WHITE + "Table not found!" )
152250 return []
153251
154252
@@ -161,7 +259,7 @@ def check_file_content(database, file_name, *border):
161259 if os .path .exists (f"databases/{ database } /files/{ file_name } .txt" ):
162260 file = open (f"databases/{ database } /files/{ file_name } .txt" , "r" )
163261
164- return [line for line in file ]
262+ return [Fore . WHITE + line for line in file ]
165263
166264 print ("File not found!" )
167265 return []
@@ -184,7 +282,7 @@ def drop_database(*databases):
184282 if os .path .exists (f"databases/{ db } /" ):
185283 shutil .rmtree (f"databases/{ db } /" )
186284
187- return "Database/s dropped!"
285+ return Fore . WHITE + "Database/s dropped!"
188286
189287
190288def drop_table (database , * tables ):
@@ -202,15 +300,15 @@ def drop_table(database, *tables):
202300 if os .path .exists (f"databases/{ database } /tables/{ table } .txt" ):
203301 os .remove (f"databases/{ database } /tables/{ table } .txt" )
204302
205- return "Table/s dropped!"
303+ return Fore . WHITE + "Table/s dropped!"
206304
207305
208306def delete_file (database , * files ):
209307 '''
210308 Console command
211309
212310 One File:
213- DEL FILE TableName
311+ DEL FILE FileName
214312
215313 More Than One File:
216314 DEL FILES FirstFileName SecondFileName ThirdFileName...
@@ -220,7 +318,7 @@ def delete_file(database, *files):
220318 if os .path .exists (f"databases/{ database } /files/{ file } .txt" ):
221319 os .remove (f"databases/{ database } /files/{ file } .txt" )
222320
223- return "File/s deleted!"
321+ return Fore . WHITE + "File/s deleted!"
224322
225323
226324def code_saver (user_input , code_file , new_line ):
@@ -234,23 +332,28 @@ def code_saver(user_input, code_file, new_line):
234332
235333
236334def 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+ 237340 while True :
238- db = input ("create or use database: " )
341+ db = input (Fore . WHITE + "create or use database: " )
239342
240343 if db == 'create' :
241- create_db = input ("database name: " )
344+ create_db = input (Fore . WHITE + "database name: " )
242345 create_database (create_db )
243346 d = use_database (create_db )
244347 break
245348
246349 elif db == "use" :
247- d = use_database (input ("database name: " ))[- 1 ]
350+ d = use_database (input (Fore . WHITE + "database name: " ))[- 1 ]
248351 break
249352
250353 database = d
251354
252355 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 " )
254357
255358 if not os .path .exists (f"src/{ file } .txt" ):
256359 f = open (f"src/{ file } .txt" , "x" )
@@ -264,15 +367,17 @@ def run_program():
264367 while True :
265368
266369 operation_code = input ()
267- operation = operation_code .lower ().split ()
268- 269- code_saver (operation_code , file , '\n ' )
270370
271371 if operation_code == "END" :
272372 break
273373
274374 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 ' )
276381
277382 if len (operation ) >= 3 :
278383 if operation [- 1 ]:
0 commit comments