survivorbat / gorm-like

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.

Home Page:https://pkg.go.dev/github.com/survivorbat/gorm-like

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ‘ Gorm Auto Like Plugin

Go package

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 the gormlike:"true" tag
  • SettingOnly(): 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.

πŸ’‘ Related Libraries

  • 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

⬇️ Installation

go get github.com/survivorbat/gorm-like

πŸ“‹ Usage

package main

import (
    "github.com/survivorbat/gorm-like"
)

func main() {
	db, _ := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
	db.Use(gormlike.New())
}

πŸ”­ Plans

Not much here.

About

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.

https://pkg.go.dev/github.com/survivorbat/gorm-like

License:MIT License


Languages

Language:Go 97.4%Language:Makefile 2.6%