I wanted to provide a map to a WHERE query and automatically turn it into a LIKE query if wildcards were present, this plugin does just that. If you want to convert queries based on prefix, you should have a look at gorm-query-convert.
By default, all queries are turned into like-queries if either a % or a given character is found, if you don't want this, you have 2 options:
TaggedOnly()
: Will only change queries on fields that have thegormlike:"true"
tagSettingOnly()
: Will only change queries on*gorm.DB
objects that have.Set("gormlike", true)
set.
If you want a particular query or field to not be like-able, use .Set("gormlike", false)
or gormlike:"false"
respectively. These work
regardless of configuration.
- deepgorm turns nested maps in WHERE-calls into subqueries
- gormqonvert turns WHERE-calls into different queries if certain tokens were found
- gormcase adds case insensitivity to WHERE queries
- gormtestutil provides easy utility methods for unit-testing with gorm
go get github.com/survivorbat/gorm-like
package main
import (
"github.com/survivorbat/gorm-like"
)
func main() {
db, _ := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
db.Use(gormlike.New())
}
Not much here.