An open API service indexing awesome lists of open source software.

https://github.com/survivorbat/gorm-deep-filtering

Allow gorm's Where() to take in maps of maps that are automatically converted into subqueries
https://github.com/survivorbat/gorm-deep-filtering

deep deep-filter deep-filtering deep-map filter filtering go go-map go-orm golang gorm gorm-orm gorm-plugin many-to-many many-to-one map map-deep multi-query one-to-many

Last synced: about 1 month ago
JSON representation

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

Awesome Lists containing this project

README

        

# 🌌 Gorm Deep Filtering Plugin

[![Go package](https://github.com/survivorbat/gorm-deep-filtering/actions/workflows/test.yaml/badge.svg)](https://github.com/survivorbat/gorm-deep-filtering/actions/workflows/test.yaml)
![GitHub](https://img.shields.io/github/license/survivorbat/gorm-deep-filtering)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/survivorbat/gorm-deep-filtering)

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

```go
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:

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

## 💡 Related Libraries

- [gormlike](https://github.com/survivorbat/gorm-like) turns WHERE-calls into LIkE queries if certain tokens were found
- [gormqonvert](https://github.com/survivorbat/gorm-query-convert) turns WHERE-calls into different queries if certain tokens were found
- [gormcase](https://github.com/survivorbat/gorm-case) adds case insensitivity to WHERE queries
- [gormtestutil](https://github.com/ing-bank/gormtestutil) provides easy utility methods for unit-testing with gorm

## ⬇️ Installation

`go get github.com/survivorbat/gorm-deep-filtering`

## 📋 Usage

```go
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.