db icon indicating copy to clipboard operation
db copied to clipboard

Using types that implement driver.Valuer in conditions

Open tooolbox opened this issue 6 years ago • 0 comments

This is not clear from the documentation, but if I use a type that implements driver.Value in a Where() or a Find(), will this package call Value() on the type as part of creating the prepared statement?

Obviously it will in the case of inserting said value into the database, but it's not clear from the documentation or the code if this will work as part of a query.

Example:

type StringThatSavesBackwards string

func (s StringThatSavesBackwards) Value() (driver.Value, error) {
    result := ""
    for _, v := range s {
        result = string(v) + result
    }
    return s, nil
}

func queryDatabase(...) {
    author := StringThatSavesBackwards("joe")
    session.Collection("books").Find("author = ?", author) // will it find "eoj"?
}

tooolbox avatar May 27 '19 02:05 tooolbox