-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathrows.py
More file actions
56 lines (39 loc) · 1.26 KB
/
rows.py
File metadata and controls
56 lines (39 loc) · 1.26 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
from seatable_api import Base
server_url = 'http://127.0.0.1:8000'
api_token = 'd67d4e0eeee24b55ff7b60595faed7e2df36e1d1'
def query():
base = Base(api_token, server_url)
base.auth()
sql = 'select name,price from table where year = 2021;'
results = base.query(sql)
def row_link():
table_name = 'Table1'
other_table_name = 'Table2'
column_name = 'Foreign Key'
base = Base(api_token, server_url)
base.auth()
# get column link id
metadata = base.get_metadata()
table = None
for table_item in metadata['tables']:
if table_item['name'] == table_name:
table = table_item
break
column = None
for column_item in table['columns']:
if column_item['name'] == column_name:
column = column_item
break
link_id = column['data']['link_id']
# get row id
rows = base.list_rows(table_name)
other_rows = base.list_rows(other_table_name)
row_id = rows[0]['_id']
other_row_id = other_rows[0]['_id']
# add link
base.add_link(link_id, table_name, other_table_name,row_id, other_row_id)
# remove link
# base.remove_link(link_id, table_name, other_table_name, row_id, other_row_id)
if __name__ == '__main__':
row_link()
query()