Skip to content

Commit 35b7a02

Browse files
committed
docs: add constructor explanation
1 parent b913f4b commit 35b7a02

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff 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
96108
Create 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+
99121
type 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+
193225
type User struct {
194226
ID uint `json:"id" gorm:"primaryKey"`
195227
Name string `json:"name"`

0 commit comments

Comments
 (0)