Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
fiatjaf opened this issue Feb 29, 2016 · 5 comments
Open

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

fiatjaf opened this issue Feb 29, 2016 · 5 comments

Comments

@fiatjaf
Copy link

fiatjaf commented Feb 29, 2016

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.

@fiatjaf
Copy link
Author

fiatjaf commented Feb 29, 2016

I'm confused, the second approach actually works for primary types (string, int, bool), just not for struct.

@fiatjaf
Copy link
Author

fiatjaf commented Feb 29, 2016

Perhaps passing a pointer to a pointer will work? I'll stop commenting.

@freeeve
Copy link
Member

freeeve commented Mar 1, 2016

Yeah, database/sql doesn't understand map types, so there's no way for sqlx to convert from a map[string]CypherValue to a struct. I'm thinking for best results we need an underlying API that's not database/sql, which is what I'm planning in v2. Unfortunately I don't think this is fixable in v1.

@fiatjaf
Copy link
Author

fiatjaf commented Mar 1, 2016

But doesn't analogous cases work with sqlx and pq, for example?

(I'm sorry if this is a stupid question, I'm not complaining, I'm just curious and want to understand more. Also, I'm not sure if I remember seeing this working in analogous cases.)

@freeeve
Copy link
Member

freeeve commented Mar 1, 2016

If you return a table.* maybe I could see it working.

On Tuesday, March 1, 2016, Giovanni T. Parra [email protected]
wrote:

But doesn't analogous cases work with sqlx and pq, for example?

(I'm sorry if this is a stupid question, I'm not complaining, I'm just
curious and want to understand more. Also, I'm not sure if I remember
seeing this working in analogous cases.)


Reply to this email directly or view it on GitHub
#27 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants