...

Source file src/github.com/ory/x/sqlxx/sqlxx_test.go

Documentation: github.com/ory/x/sqlxx

     1  package sqlxx
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  type st struct {
    11  	Foo  string `db:"foo"`
    12  	Bar  string `db:"bar,omitempty"`
    13  	Barn string `db:"barn,omitempty"`
    14  	Baz  string `db:"-"`
    15  	Zab  string
    16  }
    17  
    18  func TestNamedUpdateArguments(t *testing.T) {
    19  	assert.Equal(t,
    20  		"UPDATE foo SET foo=:foo, bar=:bar",
    21  		fmt.Sprintf("UPDATE foo SET %s", NamedUpdateArguments(new(st), "barn")),
    22  	)
    23  }
    24  
    25  func TestExpectNamedInsert(t *testing.T) {
    26  	columns, arguments := NamedInsertArguments(new(st), "barn")
    27  	assert.Equal(t,
    28  		"INSERT INTO foo (foo, bar) VALUES (:foo, :bar)",
    29  		fmt.Sprintf("INSERT INTO foo (%s) VALUES (%s)", columns, arguments),
    30  	)
    31  }
    32  

View as plain text