/gorm-deep-filtering

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

Primary LanguageGoMIT LicenseMIT

🌌 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
	db.Use(deepgorm.New())
}

🔭 Plans

Better error handling, logging.