Skip to content

sqlx's Get doesn't work with single return values #27

@fiatjaf

Description

@fiatjaf

I don't know how to phrase this better, so here's an example:

considering

type Message struct {
    Date      types.NullTime `json:"date"      db:"date"`
    Id        string         `json:"id"        db:"id"`
    From      string         `json:"from"      db:"from"`
    CommentId string         `json:"commentId" db:"commentId"`
}
message := Message{}
err := DB.Get(&message, `
MATCH (m:Message {commentId: {0}})
RETURN m.date AS date,
       m.id AS id,
       m.from as from, m.commentId as commentId`,
        commentId)

This works. message is populated according to the Message definitions.

message := Message{}
err := DB.Get(&message, `
MATCH (m:Message {commentId: {0}})
RETURN m`,
        commentId)

This doesn't work.


Now that I wrote, I can imagine why this happens and that it isn't an bug, but perhaps there is a way to make this kind of query easier. Neo4j should have a RETURN m.* statement, but it doesn't.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions