Git Product home page Git Product logo

gin-gorm-filter's People

Contributors

activechoon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gin-gorm-filter's Issues

Feasibility of filtering via many2many relationships

I'm fairly new to gorm, and only looked at this library in the past hour.

I have a set of models which I have included some simplified versions of below.
How feasible might it be to add functionality to this library that would allow filtering by User.Email when querying for a list of Devices via the Device.Users many2many relationship?
Does the library currently have any support for filtering via relationships?

type Device struct {
    ID int32  `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id" filter:"param:id;searchable;filterable"`
    Users              []*User       `gorm:"many2many:userDevice;foreignKey:id;joinForeignKey:deviceId;References:id;JoinReferences:userId"`
}

type UserDevice struct {
	ID       int32  `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id"`
	DeviceID *int32 `gorm:"column:deviceId;type:int;uniqueIndex:uniqueEntry,priority:3;index:deviceUser,priority:1" json:"deviceId"`
	UserID   *int32 `gorm:"column:userId;type:int;uniqueIndex:uniqueEntry,priority:1;index:deviceUser,priority:2" json:"userId"`
}

type User struct {
	ID                       int32      `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id"`
	Email                    string     `gorm:"column:email;type:varchar(512);not null;uniqueIndex:uniqueemail,priority:1" json:"email"`
}

Non alphanum filter value

Hi,

First, thank you for this amazing little gorm filtering module, very well thought, and super simple/easy to implement !

I open an issue to discuss about a problem we encounter.

This regex does not match non-alphanumerical value such as this string : "my-value-contains-hyphens" :

re, err := regexp.Compile(fmt.Sprintf(`(?m)%v:(\w{1,}).*`, paramName))

I think this choice has been made to let user chose any non-alphanumerical character as a separator when you have multiple filters in the string.

On our fork, we decided to choose a fixed separator (we chose ,) and replaced the regex with :

re, err := regexp.Compile(fmt.Sprintf(`(?m)%v:([^,]*)`, paramName))

And now, the filters are working with any filter value :)

Do you think it could be integrated into the main code, or you want to let it like this ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.