From 88a1677cb7a03afb2266d8c84951cfe905d0fa19 Mon Sep 17 00:00:00 2001 From: Tiscs Date: Thu, 7 Nov 2024 11:09:44 +0800 Subject: [PATCH] feat: enhance Apply method to accept multiple functions --- query_column_add.go | 7 ++++--- query_column_drop.go | 7 ++++--- query_delete.go | 8 ++++---- query_insert.go | 8 ++++---- query_merge.go | 8 ++++---- query_select.go | 8 ++++---- query_update.go | 8 ++++---- 7 files changed, 28 insertions(+), 26 deletions(-) diff --git a/query_column_add.go b/query_column_add.go index 32a21338e..3b4fe3d07 100644 --- a/query_column_add.go +++ b/query_column_add.go @@ -42,9 +42,10 @@ 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 { + q = fn(q) } return q } diff --git a/query_column_drop.go b/query_column_drop.go index 1439ed9b9..c153b34aa 100644 --- a/query_column_drop.go +++ b/query_column_drop.go @@ -40,9 +40,10 @@ 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 { + q = fn(q) } return q } diff --git a/query_delete.go b/query_delete.go index 49a750cc8..7d79d0767 100644 --- a/query_delete.go +++ b/query_delete.go @@ -44,10 +44,10 @@ 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 { + q = fn(q) } return q } diff --git a/query_insert.go b/query_insert.go index 6d38a4efe..fa040c727 100644 --- a/query_insert.go +++ b/query_insert.go @@ -53,10 +53,10 @@ 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 { + q = fn(q) } return q } diff --git a/query_merge.go b/query_merge.go index 626752b8a..112263d81 100644 --- a/query_merge.go +++ b/query_merge.go @@ -50,10 +50,10 @@ 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 { + q = fn(q) } return q } diff --git a/query_select.go b/query_select.go index 5bb329143..8f070dcbc 100644 --- a/query_select.go +++ b/query_select.go @@ -66,10 +66,10 @@ 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 { + q = fn(q) } return q } diff --git a/query_update.go b/query_update.go index e56ba20d1..d4d65850b 100644 --- a/query_update.go +++ b/query_update.go @@ -53,10 +53,10 @@ 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 { + q = fn(q) } return q }