filter

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2022 License: MIT Imports: 6 Imported by: 0

README

gorm-filter

Field Lookups

like django filter

Use

go get -u github.com/pandalzy/gorm-filter
import (
    filter "github.com/pandalzy/gorm-filter"
)

type UserFilter struct {
    Username *string       `form:"username" filter:"field:username;expr:contains"`
    Name     string        `form:"name" filter:"field:name;expr:contains"`
    Age      []interface{} `form:"age" filter:"field:age;expr:in"`
    Email    string        `form:"email" filter:"field:email;expr:exact"`
}

Example

See example/main.go

cd example
go run main.go

output

[2.411ms] [rows:1] SELECT * FROM `users` WHERE `age` IN (20,19) AND `username` LIKE '%a%' AND `name` LIKE '%l%' AND `users`.`deleted_at` IS NULL
2022/06/25 09:24:56 [{{1 2022-06-20 21:29:19 +0800 CST 2022-06-20 21:29:21 +0800 CST {0001-01-01 00:00:00 +0000 UTC false}} panda lzy 20 }]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(filter interface{}) ([]filterStruct, error)

func Query

func Query(db *gorm.DB, filter interface{}) (*gorm.DB, error)

Types

type Contains

type Contains clause.Eq

func (Contains) Build

func (c Contains) Build(builder clause.Builder)

type EndsWith

type EndsWith clause.Eq

func (EndsWith) Build

func (e EndsWith) Build(builder clause.Builder)

type IContains

type IContains clause.Eq

func (IContains) Build

func (i IContains) Build(builder clause.Builder)

type IEndsWith

type IEndsWith clause.Eq

func (IEndsWith) Build

func (i IEndsWith) Build(builder clause.Builder)

type IExact

type IExact clause.Eq

func (IExact) Build

func (i IExact) Build(builder clause.Builder)

type IStartsWith

type IStartsWith clause.Eq

func (IStartsWith) Build

func (i IStartsWith) Build(builder clause.Builder)

type StartsWith

type StartsWith clause.Eq

func (StartsWith) Build

func (s StartsWith) Build(builder clause.Builder)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL