-
-
Save mohamedaltaib/a5fe89d1ecca6e74b2e3cff0c3f21b39 to your computer and use it in GitHub Desktop.
Track tables in python (Hasura)
This file contains 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