Skip to content

Commit 94bd8cc

Browse files
authored
Added queues and edited documentation (#11)
2 parents 40e04ca + a1d11d5 commit 94bd8cc

File tree

9 files changed

+638
-10
lines changed

9 files changed

+638
-10
lines changed

ConsoleSQL.py

+110-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def create_database(database, *args):
1313

1414
try:
1515

16-
os.mkdir(f"databases/{database}"), os.mkdir(f"databases/{database}/files"), os.mkdir(f"databases/{database}/tables")
16+
os.mkdir(f"databases/{database}"), os.mkdir(f"databases/{database}/files"), os.mkdir(f"databases/{database}/tables"), os.mkdir(f"databases/{database}/queues")
1717

1818
except FileExistsError:
1919
return Fore.LIGHTWHITE_EX + "Database already exists"
@@ -138,6 +138,69 @@ def write_in_file(database, file, *content):
138138
return Fore.LIGHTWHITE_EX + f"Database \"{database}\" or File \"{file}\" not found!"
139139

140140

141+
def create_queue(database, queue_file_name, *args):
142+
'''
143+
Console command
144+
145+
CREATE QUEUE QueueName
146+
147+
or
148+
149+
CREATE QUE QueueName
150+
151+
or
152+
153+
CREATE Q QueueName
154+
'''
155+
156+
if os.path.exists(f"databases/{database}/queues/{queue_file_name}.txt"):
157+
return Fore.LIGHTWHITE_EX + "Queue already exists"
158+
159+
file = open(f"databases/{database}/queues/{queue_file_name}.txt", 'x')
160+
file.close()
161+
162+
return Fore.LIGHTWHITE_EX + f"Queue \"{queue_file_name}\" was created!"
163+
164+
165+
def add_to_queue(database, queue, *items):
166+
'''
167+
Console command
168+
ADD TO QueueName firstItem secondItem thirdItem
169+
'''
170+
171+
if os.path.exists(f"databases/{database}/queues/{queue}.txt"):
172+
with open(f"databases/{database}/queues/{queue}.txt", "a+") as q:
173+
for item in items:
174+
q.write(f"{item}\n")
175+
176+
return Fore.LIGHTWHITE_EX + "Items added to queue!"
177+
178+
return Fore.LIGHTWHITE_EX + f"Database \"{database}\" or Queue \"{queue}\" not found!"
179+
180+
181+
def remove_from_queue(database, queue, *args):
182+
'''
183+
Console command
184+
REMOVE FROM QueueName
185+
'''
186+
187+
if os.path.exists(f"databases/{database}/queues/{queue}.txt"):
188+
189+
q = [item for item in open(f"databases/{database}/queues/{queue}.txt", "r")][1:]
190+
191+
os.remove(f"databases/{database}/queues/{queue}.txt")
192+
f = open(f"databases/{database}/queues/{queue}.txt", "a+")
193+
194+
for item in q:
195+
f.write(f"{item}")
196+
197+
f.close()
198+
199+
return "First element from queue removed!"
200+
201+
return f"Queue \"{queue}\" not found!"
202+
203+
141204
def check_table_content(database, table, *args):
142205
'''
143206
Console command
@@ -168,6 +231,19 @@ def check_file_content(database, file_name, *border):
168231
return []
169232

170233

234+
def check_queue_content(database, queue, *args):
235+
'''
236+
Console command
237+
GET QueueName
238+
'''
239+
240+
if os.path.exists(f"databases/{database}/queues/{queue}.txt"):
241+
q = [line for line in open(f"databases/{database}/queues/{queue}.txt", "r")]
242+
return ', '.join(q)
243+
244+
return f"Queue {queue} not found!"
245+
246+
171247
def delete_lines(database, path, file_name, *lines):
172248
'''
173249
Console command
@@ -271,6 +347,24 @@ def delete_file(database, *files):
271347
return Fore.LIGHTWHITE_EX + "File/s deleted!"
272348

273349

350+
def delete_queue(database, *queues):
351+
'''
352+
Console command
353+
354+
One Queue:
355+
DEL QUEUE QueueName
356+
357+
More Than One Queue:
358+
DEL QUEUES FirstQueueName SecondQueueName ThirdQueueName...
359+
'''
360+
361+
for queue in queues:
362+
if os.path.exists(f"databases/{database}/queues/{queue}.txt"):
363+
os.remove(f"databases/{database}/queues/{queue}.txt")
364+
365+
return Fore.LIGHTWHITE_EX + "Queue/s deleted!"
366+
367+
274368
def code_saver(user_input, code_file, new_line):
275369
'''
276370
Saves the code in the code file.
@@ -329,7 +423,7 @@ def run_program():
329423

330424
code_saver(operation_code, file, '\n')
331425

332-
if len(operation) >= 3:
426+
if len(operation) >= 2:
333427
if operation[-1]:
334428

335429
if operation[:-1] == ["create", "database"]:
@@ -406,6 +500,15 @@ def run_program():
406500

407501
code_saver(text[-3:], file, '\n\n\n')
408502

503+
elif operation[0] == "create" and (operation[1] == "queue" or operation[1] == "que" or operation[1] == "q"):
504+
print(create_queue(database, operation[-1]))
505+
506+
elif operation[0] == "add" and operation[1] == "to":
507+
print(add_to_queue(database, operation[2], *operation[3:]))
508+
509+
elif operation[0] == "remove" and operation[1] == "from":
510+
print(remove_from_queue(database, operation[-1]))
511+
409512
elif operation[0] == "get" and operation[1] == "all":
410513

411514
lines = check_table_content(database, operation[-1])
@@ -418,6 +521,9 @@ def run_program():
418521
print()
419522
[print(line) for line in lines]
420523

524+
elif operation[0] == "get":
525+
print(check_queue_content(database, operation[-1]))
526+
421527
elif len(operation) >= 5:
422528
if operation[0] == "del" and operation[3] == "lines":
423529
try:
@@ -440,3 +546,5 @@ def run_program():
440546
if "lines" not in operation:
441547
print(delete_file(database, *operation[2:]))
442548

549+
elif operation[0] == "del" and operation[1] == "queue" or operation[1] == "queues":
550+
print(delete_queue(database, *operation[2:]))

ConsoleSQL_installer.zip

8.93 KB
Binary file not shown.

databases/mydb/queues/resturant.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
client2
2+
client3
3+
client4
4+
client5
5+
client6

documentation.py

+51-7
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ def documentation():
77
88
- Creating DataBase
99
- Using/Changing DataBase
10-
- Creating Tables and Files
10+
- Creating Tables, Files and Queues
1111
- Writing in Tables and Files
12-
- Checking the content of Tables and Files
13-
- Deleting DataBases, Tables and Files
12+
- Adding elements to Queues
13+
- Checking the content of Tables, Files and Queues
14+
- Deleting content from Tables, Files and Queues
15+
- Deleting DataBases, Tables, Files and Queues
16+
17+
- Can be used in python files.
1418
- Saves all the code in File.
1519
20+
1621
{Fore.MAGENTA + "All commands can be in upper or lower case!"}
1722
1823
{Fore.GREEN + "1.How to create DataBase:"}
@@ -58,15 +63,43 @@ def documentation():
5863
content
5964
;;;
6065
61-
{Fore.GREEN + "5.How to see the content of my Tables and Files:"}
66+
{Fore.GREEN + "5.How to create Queue:"}
67+
- To create queue, you must use one of the following commands:
68+
69+
{Fore.MAGENTA + "CREATE QUEUE QueueName"}
70+
71+
or
72+
73+
CREATE QUE QueueName
74+
75+
or
76+
77+
CREATE Q QueueName
78+
79+
{Fore.RED + '"NOTE!" You cannot remove any element from queue, every time you try to remove element, it will remove only the first one!'}
80+
81+
{Fore.GREEN + "6.How to add elements to queue:"}
82+
- To add elements in THE END of the queue, you should use this command:
83+
84+
{Fore.LIGHTMAGENTA_EX + "ADD TO QueueName firstItem secondItem thirdItem"}
85+
86+
{Fore.GREEN + "7.How to remove element from queue:"}
87+
- Use this command:
88+
89+
REMOVE FROM QueueName
90+
91+
{Fore.RED + '"NOTE!" You can only remove the first element in the queue!'}
92+
93+
{Fore.GREEN + "8.How to see the content of my Tables, Files and Queues:"}
6294
- Use this command for Tables: GET ALL TableName
6395
- Use this command for Files: GET FILE FileName
96+
- Use this command for Queues: GET QueueName
6497
65-
6.How to delete content from files/tables:
98+
9.How to delete content from files/tables:
6699
- Use this command for Tables: DEL TABLE TableName LINES firstline secondline seventhline
67100
- Use this command for Files: DEL FILE FileName LINES firstline secondline seventhline
68101
69-
7.How to delete DataBases, Tables and Files:
102+
10.How to delete DataBases, Tables, Files and Queues:
70103
- Delete DataBase/s:
71104
72105
{Fore.MAGENTA + "One DataBase:"}
@@ -93,9 +126,20 @@ def documentation():
93126
More Than One File:
94127
DEL FILES FirstFileName SecondFileName ThirdFileName...
95128
129+
{Fore.GREEN + "- Delete Queues:"}
130+
131+
{Fore.MAGENTA + "One Queue:"}
132+
DEL QUEUE QueueName
133+
134+
More Than One Queue:
135+
DEL QUEUES FirstQueueName SecondQueueName ThirdQueueName...
136+
96137
138+
{Fore.LIGHTGREEN_EX + "11.How to use the ConsoleSQL in Python code?"}
139+
- You can simply, just import the ConsoleSQL file and call the functions.
140+
For example, see the test_usages/ folder.
97141
98-
{Fore.LIGHTGREEN_EX + "8.How to save the code?"}
142+
{Fore.LIGHTGREEN_EX + "12.How to save the code?"}
99143
- The code is saving by itself in the chosen at the beginning by you file, to change the file
100144
you must stop the program and rerun it. The file can be found in the same directory "src/filename"
101145

readme.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# Python-ConsoleSQL
2-
This is an SQL for Python console. It's similar to MySql.
2+
This is an SQL for Python console. It can be used in code too.
3+
4+
### [Download Guide](#Download-guide)
5+
### [Documentation](#Documentation)
6+
7+
8+
# Download-guide
9+
10+
**Go to the files above and click on ConsoleSQL_installer.zip, then click on view raw or download.**
11+
12+
![Screenshot 2023-02-20 110454](https://user-images.githubusercontent.com/112943652/220061559-db5fc0cb-556f-4a66-90be-547d8322d00b.png)
13+
![Screenshot 2023-02-20 110540](https://user-images.githubusercontent.com/112943652/220061591-54584fe9-cf62-4d99-b51f-3691ee4f2836.png)
14+
15+
16+
# Documentation
317

418
#### Run main.py to start the program.
19+
520
#### To see the documentation, type "docs" on the console.
21+
**This is what you're gonna see.**
22+
23+
![Screenshot 2023-02-20 104656](https://user-images.githubusercontent.com/112943652/220061875-c2174bdf-adfa-4c63-9c40-0634180d7f21.png)
24+
![Screenshot 2023-02-20 104735](https://user-images.githubusercontent.com/112943652/220061869-4544ef81-c73f-47a5-a418-0ac53f21d88a.png)
25+
![Screenshot 2023-02-20 104806](https://user-images.githubusercontent.com/112943652/220061861-b48d93a0-5b35-4702-b297-ebca379e5393.png)
26+
![Screenshot 2023-02-20 104839](https://user-images.githubusercontent.com/112943652/220061882-50771220-6d42-4c6e-b56f-1061db5f5c60.png)

src/mydb.txt

+8
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,11 @@ ADD testtable VALUES (
6767
DEL TABLE testtable LINES 1 3 5
6868
GET ALL testtable
6969
GET FILE testfile
70+
71+
CREATE QUEUE resturant
72+
ADD TO resturant client1 client2 client3 client4 client5
73+
ADD TO resturant client6
74+
REMOVE FROM resturant
75+
GET resturant
76+
CREATE QUEUE deletble
77+
DEL QUEUE deletble

0 commit comments

Comments
 (0)