Skip to content

Commit

Permalink
feat: enhance Apply method to accept multiple functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiscs committed Nov 8, 2024
1 parent 1b62093 commit 028bad6
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 26 deletions.
9 changes: 6 additions & 3 deletions query_column_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ func (q *AddColumnQuery) Err(err error) *AddColumnQuery {
return q
}

func (q *AddColumnQuery) Apply(fn func(*AddColumnQuery) *AddColumnQuery) *AddColumnQuery {
if fn != nil {
return fn(q)
// Apply calls each function in fns, passing the AddColumnQuery as an argument.
func (q *AddColumnQuery) Apply(fns ...func(*AddColumnQuery) *AddColumnQuery) *AddColumnQuery {
for _, fn := range fns {
if fn != nil {
return fn(q)
}
}
return q
}
Expand Down
9 changes: 6 additions & 3 deletions query_column_drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ func (q *DropColumnQuery) Err(err error) *DropColumnQuery {
return q
}

func (q *DropColumnQuery) Apply(fn func(*DropColumnQuery) *DropColumnQuery) *DropColumnQuery {
if fn != nil {
return fn(q)
// Apply calls each function in fns, passing the DropColumnQuery as an argument.
func (q *DropColumnQuery) Apply(fns ...func(*DropColumnQuery) *DropColumnQuery) *DropColumnQuery {
for _, fn := range fns {
if fn != nil {
return fn(q)
}
}
return q
}
Expand Down
10 changes: 6 additions & 4 deletions query_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ func (q *DeleteQuery) Err(err error) *DeleteQuery {
return q
}

// Apply calls the fn passing the DeleteQuery as an argument.
func (q *DeleteQuery) Apply(fn func(*DeleteQuery) *DeleteQuery) *DeleteQuery {
if fn != nil {
return fn(q)
// Apply calls each function in fns, passing the DeleteQuery as an argument.
func (q *DeleteQuery) Apply(fns ...func(*DeleteQuery) *DeleteQuery) *DeleteQuery {
for _, fn := range fns {
if fn != nil {
return fn(q)
}
}
return q
}
Expand Down
10 changes: 6 additions & 4 deletions query_insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ func (q *InsertQuery) Err(err error) *InsertQuery {
return q
}

// Apply calls the fn passing the SelectQuery as an argument.
func (q *InsertQuery) Apply(fn func(*InsertQuery) *InsertQuery) *InsertQuery {
if fn != nil {
return fn(q)
// Apply calls each function in fns, passing the InsertQuery as an argument.
func (q *InsertQuery) Apply(fns ...func(*InsertQuery) *InsertQuery) *InsertQuery {
for _, fn := range fns {
if fn != nil {
return fn(q)
}
}
return q
}
Expand Down
10 changes: 6 additions & 4 deletions query_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ func (q *MergeQuery) Err(err error) *MergeQuery {
return q
}

// Apply calls the fn passing the MergeQuery as an argument.
func (q *MergeQuery) Apply(fn func(*MergeQuery) *MergeQuery) *MergeQuery {
if fn != nil {
return fn(q)
// Apply calls each function in fns, passing the MergeQuery as an argument.
func (q *MergeQuery) Apply(fns ...func(*MergeQuery) *MergeQuery) *MergeQuery {
for _, fn := range fns {
if fn != nil {
return fn(q)
}
}
return q
}
Expand Down
10 changes: 6 additions & 4 deletions query_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ func (q *SelectQuery) Err(err error) *SelectQuery {
return q
}

// Apply calls the fn passing the SelectQuery as an argument.
func (q *SelectQuery) Apply(fn func(*SelectQuery) *SelectQuery) *SelectQuery {
if fn != nil {
return fn(q)
// Apply calls each function in fns, passing the SelectQuery as an argument.
func (q *SelectQuery) Apply(fns ...func(*SelectQuery) *SelectQuery) *SelectQuery {
for _, fn := range fns {
if fn != nil {
return fn(q)
}
}
return q
}
Expand Down
10 changes: 6 additions & 4 deletions query_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ func (q *UpdateQuery) Err(err error) *UpdateQuery {
return q
}

// Apply calls the fn passing the SelectQuery as an argument.
func (q *UpdateQuery) Apply(fn func(*UpdateQuery) *UpdateQuery) *UpdateQuery {
if fn != nil {
return fn(q)
// Apply calls each function in fns, passing the UpdateQuery as an argument.
func (q *UpdateQuery) Apply(fns ...func(*UpdateQuery) *UpdateQuery) *UpdateQuery {
for _, fn := range fns {
if fn != nil {
return fn(q)
}
}
return q
}
Expand Down

0 comments on commit 028bad6

Please sign in to comment.