forked from Attakay78/Pytql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
91 lines (75 loc) · 2.51 KB
/
example.py
File metadata and controls
91 lines (75 loc) · 2.51 KB
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
# Example
from pytql.model import Model
from pytql.fields import CharField, IntField
from pytql.colors import Color
from pytql.table import Table
from pytql.repl import start_client, ReplType
if __name__ == "__main__":
class Student(Model):
first_name = CharField(name="First Name", max_length=20)
last_name = CharField()
age = IntField()
length = IntField()
class Employee(Model):
first_name = CharField(name="First Name", max_length=40)
last_name = CharField(name="Last Name")
password = CharField()
city = CharField()
# Data to populate Student table.
student_data = [
["Richard", "Quaicoe", 23, 243],
["Mike", "Kuam", 33, 123],
["Roynam", "Skim", 13, 56],
["Leon", "Santa", 29, 23],
["Geroge"],
]
# Example with passing data with `Student` Model.
student_table = Table(
model=Student,
data=student_data,
header_color=Color.cyan,
row_color=Color.green,
table_color=Color.red,
)
# Example with passing file data with `Employee` Model.
employee_table = Table(
model=Employee,
file="user_data.json",
header_color=Color.cyan,
row_color=Color.green,
table_color=Color.blue,
)
# Draw student table
student_table.draw_table()
# # Add new row to student row at position 3
student_table.add_row(["Jon", "Doe", 23, 232], position=3)
student_table.draw_table(student_table.get_data())
query_data = (
student_table.query()
.filter_by("First Name")
.equals("Richard")
.filter_by("length")
.greater_than("20")
.end_query()
)
student_table.draw_table(query_data)
# # Query student table by filtering `First Name`.
t2 = student_table.query().filter_by("First Name").equals("Richard").end_query()
student_table.draw_table(t2)
# # Query student table by filtering with `First Name` and `length` columns.
t1 = (
student_table.query()
.filter_by("First Name")
.equals("Richard")
.filter_by("length")
.greater_than("20")
.end_query()
)
student_table.draw_table(t1)
# # # Update student `age` column
student_table.update("age").where("33", "67")
student_table.draw_table()
# # # NB: Same operations perform on Student table can be performed on Employee table
employee_table.draw_table(employee_table.get_data())
# Start cli client
start_client(__name__, repl_type=ReplType.ipython_repl)