activechoon / gin-gorm-filter Goto Github PK
View Code? Open in Web Editor NEWFilter GORM query with query params
License: MIT License
Filter GORM query with query params
License: MIT License
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"`
}
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 ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.