Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Returning values partially in SQL returning array instead of object #2423

Unanswered
Jumaniyozov asked this question in Q&A
Discussion options

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

image

You must be logged in to vote

Replies: 1 comment

Comment options

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

image

I think it's because of generated code where as return value it's using interface{}

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /