File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -91,11 +91,33 @@ curl "http://localhost:8080/users?search=admin&sort=id,desc&page=2&per_page=5"
9191
9292## 🗂️ Advanced Filtering
9393
94- ### Custom Filter Pattern with Validation
94+ Use this constructor in every implemented builder.
95+ ``` go
96+ type XQuery struct {
97+ db *gorm.DB
98+ }
9599
100+ func NewXQuery (db *gorm .DB ) *XQuery {
101+ return &XQuery{
102+ db: db,
103+ }
104+ }
105+ ```
106+
107+ ### Custom Filter Pattern with Validation
96108Create powerful, reusable filters with automatic validation:
97109
98110``` go
111+ type UserQuery struct {
112+ db *gorm.DB
113+ }
114+
115+ func NewUserQuery (db *gorm .DB ) *UserQuery {
116+ return &UserQuery{
117+ db: db,
118+ }
119+ }
120+
99121type UserFilter struct {
100122 pagination.BaseFilter
101123 ID int ` json:"id" form:"id"`
@@ -190,6 +212,16 @@ curl "http://localhost:8080/users?role=user&is_active=true&min_age=25&search=dev
190212### Basic Relationship Loading with Security
191213
192214``` go
215+ type UserQuery struct {
216+ db *gorm.DB
217+ }
218+
219+ func NewUserQuery (db *gorm .DB ) *UserQuery {
220+ return &UserQuery{
221+ db: db,
222+ }
223+ }
224+
193225type User struct {
194226 ID uint ` json:"id" gorm:"primaryKey"`
195227 Name string ` json:"name"`
You can’t perform that action at this time.
0 commit comments