-
Notifications
You must be signed in to change notification settings - Fork 923
Returning values partially in SQL returning array instead of object #2423
-
Hi, I have a following query in which I'm partially returning values:
-- name: CreateUser :one
INSERT INTO users (email, username, password, isactive, created_at, updated_at)
VALUES (1,ドル 2,ドル 3,ドル 4,ドル 5,ドル 6ドル)
RETURNING (id, email, username, isactive, created_at, updated_at);
And returning in following way:
userCreated, err := controller.queries.CreateUser(cctx, userParams)
if err != nil {
controller.logger.Error(err.Error())
return c.JSON(http.StatusBadRequest, err)
}
return c.JSON(http.StatusOK, userCreated)
But in return receiving an array not an object. How can I get object? I also tried parsing it to custom struct but getting an error saying json: cannot unmarshal array into Go value of type domain.UserReturnDTO
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
Hi, I have a following query in which I'm partially returning values:
-- name: CreateUser :one INSERT INTO users (email, username, password, isactive, created_at, updated_at) VALUES (1,ドル 2,ドル 3,ドル 4,ドル 5,ドル 6ドル) RETURNING (id, email, username, isactive, created_at, updated_at);
And returning in following way:
userCreated, err := controller.queries.CreateUser(cctx, userParams) if err != nil { controller.logger.Error(err.Error()) return c.JSON(http.StatusBadRequest, err) } return c.JSON(http.StatusOK, userCreated)
But in return receiving an array not an object. How can I get object? I also tried parsing it to custom struct but getting an error saying
json: cannot unmarshal array into Go value of type domain.UserReturnDTO
I think it's because of generated code where as return value it's using interface{}
Beta Was this translation helpful? Give feedback.