Last active
September 16, 2021 19:24
-
-
Save coco98/2a65f9fe8c1c0f5e4bee92d8cb66bc4c to your computer and use it in GitHub Desktop.
Track tables in python (Hasura)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
#Fetch existing tables | |
tables = requests.post('http://localhost:8080/v1/query', json={ | |
"type":"select", | |
"args":{ | |
"table": {"schema": "information_schema", "name": "tables"}, | |
"columns": ["table_name"], | |
"where": {"table_schema": {"$eq": "public"}} | |
} | |
}).json() | |
#Fetch tracked tables | |
tracked_tables = requests.post('http://localhost:8080/v1/query', json={ | |
"type":"select", | |
"args":{ | |
"table": {"schema": "hdb_catalog", "name": "hdb_table"}, | |
"columns": ["table_name"], | |
"where": {"table_schema": {"$eq": "public"}} | |
} | |
}).json() | |
tracked_table_names = [t['table_name'] for t in tracked_tables] | |
# Now track these tables one by one | |
for t in tables: | |
table_name = t['table_name'] | |
#Skip an already tracked table | |
if (table_name in tracked_table_names): | |
print ("Skipping. Table alread tracked: " + table_name) | |
else: | |
print(table_name) | |
response = requests.post('http://localhost:8080/v1/query', json={ | |
"type": "track_table", | |
"args": { | |
"name": table_name, | |
"schema": "public" | |
} | |
}) | |
print (response.json()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment