-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be60f13
commit 93fd637
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Multi-Filter | ||
|
||
The `multifilter` example demonstrates how to use the `multifilter`. The `multifilter` effectively is the same as using | ||
multiple `patcher.WithWhere` filters, but it is more efficient and potentially more readable. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/jacobbrewer1/patcher" | ||
) | ||
|
||
type ExampleFilter struct { | ||
Field string | ||
Value any | ||
} | ||
|
||
func (e ExampleFilter) Where() (string, []any) { | ||
return fmt.Sprintf("%s = ?", e.Field), []any{e.Value} | ||
} | ||
|
||
func main() { | ||
// Create example filters | ||
filters := []ExampleFilter{ | ||
{Field: "name", Value: "John"}, | ||
{Field: "age", Value: 30}, | ||
} | ||
|
||
mf := patcher.NewMultiFilter() | ||
|
||
// Append each filter to the WHERE clause | ||
for _, filter := range filters { | ||
mf.Add(filter) | ||
} | ||
|
||
// Print the WHERE clause | ||
sql, args := mf.Where() | ||
fmt.Printf("WHERE SQL:\n%s\n", sql) | ||
fmt.Printf("WHERE Args: %v\n", args) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.