Function relocation.

This commit is contained in:
go-jet 2019-07-20 17:44:43 +02:00
parent de34095ece
commit 1ae76d5efd
7 changed files with 15 additions and 10 deletions

View file

@ -200,7 +200,7 @@ func (q *sqlBuilder) insertParametrizedArgument(arg interface{}) {
}
func argToString(value interface{}) string {
if isNil(value) {
if utils.IsNil(value) {
return "NULL"
}

View file

@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"github.com/go-jet/jet/execution/internal"
"github.com/go-jet/jet/internal/utils"
"reflect"
"strconv"
"strings"
@ -17,7 +18,7 @@ import (
// Destination can be either pointer to struct or pointer to slice of structs.
func Query(context context.Context, db DB, query string, args []interface{}, destinationPtr interface{}) error {
if destinationPtr == nil {
if utils.IsNil(destinationPtr) {
return errors.New("jet: Destination is nil")
}

View file

@ -5,6 +5,7 @@ import (
"database/sql"
"errors"
"github.com/go-jet/jet/execution"
"github.com/go-jet/jet/internal/utils"
)
// InsertStatement is interface for SQL INSERT statements
@ -82,7 +83,7 @@ func (i *insertStatementImpl) Sql() (sql string, args []interface{}, err error)
queryData.newLine()
queryData.writeString("INSERT INTO")
if isNil(i.table) {
if utils.IsNil(i.table) {
return "", nil, errors.New("jet: table is nil")
}

View file

@ -6,6 +6,7 @@ import (
"go/format"
"os"
"path/filepath"
"reflect"
"strconv"
"strings"
"text/template"
@ -154,3 +155,7 @@ func FormatTimestamp(t time.Time) []byte {
}
return b
}
func IsNil(v interface{}) bool {
return v == nil || (reflect.ValueOf(v).Kind() == reflect.Ptr && reflect.ValueOf(v).IsNil())
}

View file

@ -2,6 +2,7 @@ package jet
import (
"errors"
"github.com/go-jet/jet/internal/utils"
)
type table interface {
@ -239,7 +240,7 @@ func (t *joinTable) serialize(statement statementType, out *sqlBuilder, options
return errors.New("jet: Join table is nil. ")
}
if isNil(t.lhs) {
if utils.IsNil(t.lhs) {
return errors.New("jet: left hand side of join operation is nil table")
}
@ -262,7 +263,7 @@ func (t *joinTable) serialize(statement statementType, out *sqlBuilder, options
out.writeString("CROSS JOIN")
}
if isNil(t.rhs) {
if utils.IsNil(t.rhs) {
return errors.New("jet: right hand side of join operation is nil table")
}

View file

@ -5,6 +5,7 @@ import (
"database/sql"
"errors"
"github.com/go-jet/jet/execution"
"github.com/go-jet/jet/internal/utils"
)
// UpdateStatement is interface of SQL UPDATE statement
@ -62,7 +63,7 @@ func (u *updateStatementImpl) Sql() (sql string, args []interface{}, err error)
out.newLine()
out.writeString("UPDATE")
if isNil(u.table) {
if utils.IsNil(u.table) {
return "", nil, errors.New("jet: table to update is nil")
}

View file

@ -124,10 +124,6 @@ func columnListToProjectionList(columns []Column) []projection {
return ret
}
func isNil(v interface{}) bool {
return v == nil || (reflect.ValueOf(v).Kind() == reflect.Ptr && reflect.ValueOf(v).IsNil())
}
func valueToClause(value interface{}) clause {
if clause, ok := value.(clause); ok {
return clause