CoCalc Public FilesPublic / PYTHON / 04-set-query.ipynbOpen with one click!
Author: ℏal Snyder
Views : 430
Description: Using the query API call
Compute Environment: Ubuntu 18.04 (Deprecated)

Use API query to set values in CoCalc database

In [ ]:
# import utility definitions %run ./01-utils.ipynb
In [ ]:
# Query A - update project description # Modify my_proj_id to be the id of one of your projects, obtained from 03-get-query.ipynb my_proj_id = '..enter your project_id here..' new_desc = "New Project Description" # Do a set query to change the description payload = {"query":{"projects":{"project_id":my_proj_id, "description":new_desc}}} response = call_api("query", payload) print("response to set query:") pp.pprint(response) # Do a get query to confirm the new setting payload = {"query":{"projects":{"project_id":my_proj_id, "description":None}}} response = call_api("query", payload) print("\nupdated project info:") pp.pprint(response)
In [ ]:
# Query B - set one attribute in a map field # This example uses the 'accounts' table account_id = 'enter the account id from notebook 02-get-my-account-id.ipynb' # set jupyter_classic editor option to False payload = {"query":{"accounts":{"account_id":account_id, "editor_settings":{"jupyter_classic":False}}}} response = call_api("query", payload) print("response to set query:") pp.pprint(response) # get list of editor_settings to confirm the update payload = {"query":{"accounts":{"account_id":account_id, "editor_settings":None}}} response = call_api("query", payload) print("\nupdated editor_settings jupyter_classic:") pp.pprint(response)
In [ ]: