Using pystardog
I am uploading stored queries. Here is the code I use pystardog
code:
# Pull query data from file
with open(query_file_path, 'r') as f:
query_options = json.load(f)
# Extract the needed information
query_name = query_options.pop("name")
query_text = query_options.pop("query")
# Add build_database to options
query_options["database"] = build_database
# Handle 'None' values
for key, value in query_options.items():
if value == None:
query_options[key] = 'None'
# Push to Stardog cloud
try:
with stardog.admin.Admin(**conn_details) as admin:
admin.new_stored_query(name=query_name, query=query_text, options=query_options)
except Exception as err:
print(f'Query likely exists. Error: {err}')
An example of the data stored in query_file_path
is
{"name": "is-child-event-Query", "description": null, "creator": "hall0ween", "query": query_text_hidden, "shared": true, "reasoning": true}
Let's assume I have blank dev
and test
databases and the build_database
variable is originally set to dev
. The code functions as intended and uploads the queries without issues. If I then re-run the code changing build_database
to test, I receive the feedback:
Error: [422] QE0QE2: Stored query already exists: is-child-event-Query
Is it possible to load queries of the same name to different databases? Thanks!