Laziness rules, why write GORM queries if you can simply add prefixes to a map[string]any
's values and automatically
convert queries to use different operators. All prefix characters can be custom-defined and are only enabled if you define them.
The currently supported queries are:
WHERE x != y
WHERE x >= y
WHERE x > y
WHERE x <= y
WHERE x < y
WHERE x LIKE y
WHERE x NOT LIKE y
By default, all queries are converted, if you want it to be more specific use:
SettingOnly()
: Will only change queries on*gorm.DB
objects that have.Set("gormqonvert", true)
set.
If you want a particular query to not be converted, use .Set("gormqonvert", false)
. This works
regardless of configuration.
- deepgorm turns nested maps in WHERE-calls into subqueries
- gormlike turns WHERE-calls into LIkE 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-query-convert
package main
import (
"github.com/survivorbat/gorm-query-convert"
)
func main() {
db, _ := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
config := gormqonvert.CharacterConfig{
GreaterThanPrefix: ">",
GreaterOrEqualToPrefix: ">=",
LessThanPrefix: "<",
LessOrEqualToPrefix: "<=",
NotEqualToPrefix: "!=",
LikePrefix: "~",
NotLikePrefix: "!~",
}
db.Use(gormqonvert.New(config))
}
Not much here.