A Go (golang) package that enhances the standard database/sql package by providing powerful data retrieval methods as well as DB-agnostic query building capabilities.
MIT License
636
stars
91
forks
source link
Should the `Query.One()` method imply a limit of one? #87
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)
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 aLIMIT 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 aLIMIT 1
? If not, I would recommend this be very clearly advertised in the documentation.