Skip to content

WilliamDeKeyzer/gorm-deep-filtering

 
 

Repository files navigation

🌌 Gorm Deep Filtering Plugin

Go package GitHub GitHub go.mod Go version

Ever wanted to filter objects on a deep level using only maps? This plugin allows you to do just that.

package main

func main () {
	filters := map[string]any{
		"name": "abc",
		"related_object": map[string]any{
			"title": "engineer",
		},
	}
}

Is automatically turned into a query that looks like this:

SELECT * FROM employees WHERE related_object_id IN (SELECT id FROM occupations WHERE title = "engineer")

💡 Related Libraries

  • gormlike turns WHERE-calls into LIkE queries if certain tokens were found
  • 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-deep-filtering

📋 Usage

package main

import (
    "github.com/survivorbat/gorm-deep-filtering"
)

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

	// Adds deep filtering
	if err := db.Use(deepgorm.New()); err != nil {
		panic(err.Error())
	}
}

🔭 Plans

Better error handling, logging.

About

Allow gorm's Where() to take in maps of maps that are automatically converted into subqueries

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 99.6%
  • Makefile 0.4%