Skip to content

Commit

Permalink
rename Apply to Compile
Browse files Browse the repository at this point in the history
  • Loading branch information
sanggonlee committed Aug 21, 2021
1 parent 6576261 commit 3bd2db9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
// It provides a very simple syntax to inject arbitrary conditional query piece.
//
// q, err := gosq.Apply(`
// q, err := gosq.Compile(`
// SELECT
// products.*
// {{ [if] .IncludeReviews [then] ,json_agg(reviews) AS reviews }}
Expand Down
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ It provides syntax to inject arbitrary conditional query piece.
## Usage

```go
q, err := gosq.Apply(`
q, err := gosq.Compile(`
SELECT
products.*
{{ [if] .IncludeReviews [then] ,json_agg(reviews) AS reviews }}
Expand All @@ -32,7 +32,7 @@ q, err := gosq.Apply(`
or

```go
q, err := gosq.Apply(`
q, err := gosq.Compile(`
SELECT
products.*
{{ [if] .IncludeReviews [then] ,json_agg(reviews) AS reviews }}
Expand Down Expand Up @@ -148,7 +148,7 @@ func getProducts(includeReviews bool) {
type queryArgs struct {
IncludeReviews bool
}
q, err := gosq.Apply(`
q, err := gosq.Compile(`
SELECT
products.*
{{ [if] .IncludeReviews [then] ,json_agg(reviews) AS reviews }}
Expand Down
6 changes: 3 additions & 3 deletions gosq.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/sanggonlee/gosq/ast"
)

// Apply receives a query template and a map of parameters, and replaces
// Compile receives a query template and a map of parameters, and replaces
// the expressions in the query template based on the values of the parameters.
//
// "args" can either be a map of parameters (map[string]interface{}), or a
Expand All @@ -31,8 +31,8 @@ import (
// }}
//
// If you need grammar for a more complex expression and you think it's a common
// use case, please file an issue in GitHub.
func Apply(template string, args interface{}) (string, error) {
// use case, please file an issue on GitHub.
func Compile(template string, args interface{}) (string, error) {
if args == nil {
return template, nil
}
Expand Down
4 changes: 2 additions & 2 deletions gosq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/sanggonlee/gosq"
)

func TestApply(t *testing.T) {
func TestCompile(t *testing.T) {
cases := []struct {
desc string
inputTemplate string
Expand Down Expand Up @@ -247,7 +247,7 @@ func TestApply(t *testing.T) {
}
for _, c := range cases {
t.Run(c.desc, func(t *testing.T) {
result, err := gosq.Apply(c.inputTemplate, c.inputArgs)
result, err := gosq.Compile(c.inputTemplate, c.inputArgs)
if whitespaceNormalized(result) != whitespaceNormalized(c.expected) {
t.Errorf("Expected %s, got %s", c.expected, result)
}
Expand Down

0 comments on commit 3bd2db9

Please sign in to comment.