You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having trouble inserting JSON data serialized as a byte string into an EdgeDB query. I'm using the orjson library to serialize the JSON into a byte string, and I want to decode and insert this data into the database using the json_array_unpack function.
Here is the code I'm trying to use:
importorjsonfromedgedbimportcreate_async_client# Data to serializedata= [{"name": "example_name"}]
# Serializing the data to a byte string JSONserialized_data=orjson.dumps(data)
# Creating the EdgeDB client (assuming you have the correct client configuration)client=create_async_client()
asyncdefinsert_data(client, serialized_data):
awaitclient.query_json(""" WITH raw_data := <json>$data FOR item IN json_array_unpack(raw_data) UNION ( UPDATE Post SET { name := item['name'] } ) """, data=serialized_data)
# Calling the data insertion functionimportasyncioasyncio.run(insert_data(client, serialized_data))
Problem:
When trying to execute the query, I am unable to insert the data correctly. I've tried various configurations, but it seems that the database is not properly interpreting the byte string JSON that I'm passing as the $data parameter.
Questions:
How should I correctly pass a byte string JSON in the EdgeDB query?
Is there a better way to handle and decode byte string JSONs directly within the EdgeDB query?
Could someone provide a working example of how to do this?
Any help would be greatly appreciated!
The text was updated successfully, but these errors were encountered:
Hello everyone,
I'm having trouble inserting JSON data serialized as a byte string into an EdgeDB query. I'm using the
orjson
library to serialize the JSON into a byte string, and I want to decode and insert this data into the database using thejson_array_unpack
function.Here is the code I'm trying to use:
Problem:
When trying to execute the query, I am unable to insert the data correctly. I've tried various configurations, but it seems that the database is not properly interpreting the byte string JSON that I'm passing as the
$data
parameter.Questions:
Any help would be greatly appreciated!
The text was updated successfully, but these errors were encountered: