-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery.py
More file actions
44 lines (39 loc) · 1.12 KB
/
Copy pathquery.py
File metadata and controls
44 lines (39 loc) · 1.12 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
# this file will converts python into filtering logic
class query_set:
def __init__(self, table):
self.table = table
# filter
def filter(self, **kwargs):
result = []
for row in self.table:
match = True
for k, v in kwargs.items():
if row.get(k) != v:
match = False
if match:
result.append(row)
return result
# get
def get(self, **kwargs):
for row in self.table:
match = True
for k, v in kwargs.items():
if row.get(k) != v:
match = False
if match:
return row
return None
# update
def update(self, where, **new_values):
for row in self.table:
if all(row[k] == v for k, v in where.items()):
row.update(new_values)
# delete
def delete(self, **where):
self.table[:] = [
row for row in self.table
if not all(row[k] == v for k, v in where.items())
]
# all
def all(self):
return self.table