addshore / gorm-deep-filtering

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

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🌌 Gorm Deep Filtering Plugin

Go package

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")

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

🔭 Plans

Better error handling, logging.

About

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

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

License:MIT License


Languages

Language:Go 99.5%Language:Makefile 0.5%