Description
Feature Request
Describe the Feature Request
We request the ability to use json.RawMessage or a similar type to insert JSON fields into YDB with positional aruguments. This feature is crucial for efficiently handling JSON data within YDB, especially when using the go_query_bind=positional modifier, which does not require table.ValueParam(s). Currently, type conversion in YDB fails when dealing with the JSON type in the database.
Describe Preferred Solution
The preferred solution would involve enhancing YDB's schema and query capabilities to support fields of type json.RawMessage. This type should seamlessly store and retrieve JSON data, preserving its structure and content. This feature should allow direct insertion and querying of JSON fields, enabling developers to work with JSON data more naturally and efficiently, even when using the go_query_bind=positional modifier.
Describe Alternatives
Alternatives considered include:
Converting JSON data to string format before insertion and parsing it upon retrieval. This method is less efficient and error-prone, as it involves additional processing and potential data integrity issues.
Using custom serialization and deserialization logic, which adds complexity to the application code and increases the maintenance burden.
Related Code
type Data struct {
ID string `json:"id"`
Name string `json:"name"`
Config json.RawMessage `json:"config"` // JSON data as RawMessage
}
data := Data{
ID: "123",
Name: "Example",
Config: json.RawMessage(`{"setting1": true, "setting2": "value"}`),
}
// With SQLX that helps to construct query with positional parameters
_, err := r.ydb.NamedExecContext(ctx, query, service.StructToMap(data)) // Does not work with json.RawMessage
I have not found options to insert JSON type to YDB with go_query_bind=positional
Additional Context
In internal/bind/params.go add:
case json.RawMessage:
return types.JSONValueFromBytes(x), nil
If the feature request is approved, would you be willing to submit a PR?
Yes