Skip to content
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

Should the Query.One() method imply a limit of one? #87

Open
mheffner opened this issue Mar 17, 2020 · 0 comments
Open

Should the Query.One() method imply a limit of one? #87

mheffner opened this issue Mar 17, 2020 · 0 comments

Comments

@mheffner
Copy link

When using the Query.One method to populate a single row from the database (like below), it would seem to me like the implication is that it will only select a single row by adding a LIMIT 1 to the query. However, it appears to run the full query without a limit and drops all but the first row. This can be quite expensive if you weren't expecting it.

Should Query.One() add a LIMIT 1? If not, I would recommend this be very clearly advertised in the documentation.

q := db.NewQuery("SELECT id, name FROM users ORDER BY id")

// populate the first row into a User struct
err = q.One(&user)
fmt.Println(user.ID, user.Name)
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

1 participant