Function relocation.
This commit is contained in:
parent
de34095ece
commit
1ae76d5efd
7 changed files with 15 additions and 10 deletions
|
|
@ -200,7 +200,7 @@ func (q *sqlBuilder) insertParametrizedArgument(arg interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func argToString(value interface{}) string {
|
func argToString(value interface{}) string {
|
||||||
if isNil(value) {
|
if utils.IsNil(value) {
|
||||||
return "NULL"
|
return "NULL"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-jet/jet/execution/internal"
|
"github.com/go-jet/jet/execution/internal"
|
||||||
|
"github.com/go-jet/jet/internal/utils"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -17,7 +18,7 @@ import (
|
||||||
// Destination can be either pointer to struct or pointer to slice of structs.
|
// 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 {
|
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")
|
return errors.New("jet: Destination is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/go-jet/jet/execution"
|
"github.com/go-jet/jet/execution"
|
||||||
|
"github.com/go-jet/jet/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InsertStatement is interface for SQL INSERT statements
|
// InsertStatement is interface for SQL INSERT statements
|
||||||
|
|
@ -82,7 +83,7 @@ func (i *insertStatementImpl) Sql() (sql string, args []interface{}, err error)
|
||||||
queryData.newLine()
|
queryData.newLine()
|
||||||
queryData.writeString("INSERT INTO")
|
queryData.writeString("INSERT INTO")
|
||||||
|
|
||||||
if isNil(i.table) {
|
if utils.IsNil(i.table) {
|
||||||
return "", nil, errors.New("jet: table is nil")
|
return "", nil, errors.New("jet: table is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"go/format"
|
"go/format"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
@ -154,3 +155,7 @@ func FormatTimestamp(t time.Time) []byte {
|
||||||
}
|
}
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsNil(v interface{}) bool {
|
||||||
|
return v == nil || (reflect.ValueOf(v).Kind() == reflect.Ptr && reflect.ValueOf(v).IsNil())
|
||||||
|
}
|
||||||
|
|
|
||||||
5
table.go
5
table.go
|
|
@ -2,6 +2,7 @@ package jet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/go-jet/jet/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type table interface {
|
type table interface {
|
||||||
|
|
@ -239,7 +240,7 @@ func (t *joinTable) serialize(statement statementType, out *sqlBuilder, options
|
||||||
return errors.New("jet: Join table is nil. ")
|
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")
|
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")
|
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")
|
return errors.New("jet: right hand side of join operation is nil table")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/go-jet/jet/execution"
|
"github.com/go-jet/jet/execution"
|
||||||
|
"github.com/go-jet/jet/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UpdateStatement is interface of SQL UPDATE statement
|
// UpdateStatement is interface of SQL UPDATE statement
|
||||||
|
|
@ -62,7 +63,7 @@ func (u *updateStatementImpl) Sql() (sql string, args []interface{}, err error)
|
||||||
out.newLine()
|
out.newLine()
|
||||||
out.writeString("UPDATE")
|
out.writeString("UPDATE")
|
||||||
|
|
||||||
if isNil(u.table) {
|
if utils.IsNil(u.table) {
|
||||||
return "", nil, errors.New("jet: table to update is nil")
|
return "", nil, errors.New("jet: table to update is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
4
utils.go
4
utils.go
|
|
@ -124,10 +124,6 @@ func columnListToProjectionList(columns []Column) []projection {
|
||||||
return ret
|
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 {
|
func valueToClause(value interface{}) clause {
|
||||||
if clause, ok := value.(clause); ok {
|
if clause, ok := value.(clause); ok {
|
||||||
return clause
|
return clause
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue