ozzo-dbx icon indicating copy to clipboard operation
ozzo-dbx copied to clipboard

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

Open mheffner opened this issue 5 years ago • 0 comments

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)

mheffner avatar Mar 17 '20 21:03 mheffner