Skip to content

Commit

Permalink
adding mocks and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacobbrewer1 committed Jan 22, 2025
1 parent be60f13 commit 93fd637
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
4 changes: 4 additions & 0 deletions examples/multifilter/README.md
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.
36 changes: 36 additions & 0 deletions examples/multifilter/main.go
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)
}
59 changes: 59 additions & 0 deletions mock_MultiFilter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 93fd637

Please sign in to comment.