-
Notifications
You must be signed in to change notification settings - Fork 1
/
workshop_exercise.py
80 lines (68 loc) · 2 KB
/
workshop_exercise.py
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
import requests
import json
host = 'http://oep.iks.cs.ovgu.de'
name = "MartinGlauer"
def create_table():
data = { 'schema': 'workshop',
'table': 'workshop_'+name.lower(),
'fields':[
{'name': 'id', 'type':'BIGSERIAL', 'pk':True},
{'name': 'name', 'type': 'VARCHAR(100)'},
{'name': 'affiliation', 'type': 'VARCHAR(100)'},
{'name': 'source', 'type': 'BIGINT'},
],
'constraints':{
'fk':[
{
'names':['source'],
'schema': 'reference',
'table': 'entries',
'fields': ['entries_id']
}
]
}
}
res= requests.post(host+'/api/create', data={'query':json.dumps(data)})
print(res)
def search_data():
data = {
'from':[{
'type': 'table',
'schema': 'workshop',
'table': 'workshop_'+name.lower()
}],
'fields':[
_get_column_query('id'),
_get_column_query('name'),
_get_column_query('affiliation'),
_get_column_query('source'),
],
'order_by':[
{
'type': 'column',
'column': 'id',
'ordering': 'desc'
}]
}
res = requests.post(host+'/api/search', data={'query':json.dumps(data)})
for row in res:
print(row)
def insert_data():
rows = [
{'name':'Max Mustermann', 'affiliation':'OvGU', 'source':'1'},
{'name':'John Doe', 'affiliation':'RLI', 'source':'2'},
{'name':'Petra Mustermann', 'affiliation':'ZNES', 'source':'3'}]
data = { 'schema': 'workshop',
'table': 'workshop_'+name.lower(),
'values': rows,
}
res = requests.post(host+'/api/insert', data={'query':json.dumps(data)})
print(res)
def _get_column_query(name):
return {
'type': 'column',
'column': name,
}
#create_table()
#insert_data()
search_data()