Fix linter errors.
This commit is contained in:
parent
57aa62f483
commit
2487c48428
14 changed files with 100 additions and 37 deletions
|
|
@ -14,7 +14,7 @@ type Dialect interface {
|
|||
// SerializerFunc func
|
||||
type SerializerFunc func(statement StatementType, out *SQLBuilder, options ...SerializeOption)
|
||||
|
||||
//// SerializeOverride func
|
||||
// SerializeOverride func
|
||||
type SerializeOverride func(expressions ...Serializer) SerializerFunc
|
||||
|
||||
// QueryPlaceholderFunc func
|
||||
|
|
|
|||
|
|
@ -8,25 +8,26 @@ type Expression interface {
|
|||
GroupByClause
|
||||
OrderByClause
|
||||
|
||||
// Test expression whether it is a NULL value.
|
||||
// IS_NULL tests expression whether it is a NULL value.
|
||||
IS_NULL() BoolExpression
|
||||
// Test expression whether it is a non-NULL value.
|
||||
// IS_NOT_NULL tests expression whether it is a non-NULL value.
|
||||
IS_NOT_NULL() BoolExpression
|
||||
|
||||
// Check if this expressions matches any in expressions list
|
||||
// IN checks if this expressions matches any in expressions list
|
||||
IN(expressions ...Expression) BoolExpression
|
||||
// Check if this expressions is different of all expressions in expressions list
|
||||
// NOT_IN checks if this expressions is different of all expressions in expressions list
|
||||
NOT_IN(expressions ...Expression) BoolExpression
|
||||
|
||||
// The temporary alias name to assign to the expression
|
||||
// AS the temporary alias name to assign to the expression
|
||||
AS(alias string) Projection
|
||||
|
||||
// Expression will be used to sort query result in ascending order
|
||||
// ASC expression will be used to sort query result in ascending order
|
||||
ASC() OrderByClause
|
||||
// Expression will be used to sort query result in ascending order
|
||||
// DESC expression will be used to sort query result in ascending order
|
||||
DESC() OrderByClause
|
||||
}
|
||||
|
||||
// ExpressionInterfaceImpl implements Expression interface methods
|
||||
type ExpressionInterfaceImpl struct {
|
||||
Parent Expression
|
||||
}
|
||||
|
|
@ -35,30 +36,37 @@ func (e *ExpressionInterfaceImpl) fromImpl(subQuery SelectTable) Projection {
|
|||
return e.Parent
|
||||
}
|
||||
|
||||
// IS_NULL tests expression whether it is a NULL value.
|
||||
func (e *ExpressionInterfaceImpl) IS_NULL() BoolExpression {
|
||||
return newPostfixBoolOperatorExpression(e.Parent, "IS NULL")
|
||||
}
|
||||
|
||||
// IS_NOT_NULL tests expression whether it is a non-NULL value.
|
||||
func (e *ExpressionInterfaceImpl) IS_NOT_NULL() BoolExpression {
|
||||
return newPostfixBoolOperatorExpression(e.Parent, "IS NOT NULL")
|
||||
}
|
||||
|
||||
// IN checks if this expressions matches any in expressions list
|
||||
func (e *ExpressionInterfaceImpl) IN(expressions ...Expression) BoolExpression {
|
||||
return newBinaryBoolOperatorExpression(e.Parent, WRAP(expressions...), "IN")
|
||||
}
|
||||
|
||||
// NOT_IN checks if this expressions is different of all expressions in expressions list
|
||||
func (e *ExpressionInterfaceImpl) NOT_IN(expressions ...Expression) BoolExpression {
|
||||
return newBinaryBoolOperatorExpression(e.Parent, WRAP(expressions...), "NOT IN")
|
||||
}
|
||||
|
||||
// AS the temporary alias name to assign to the expression
|
||||
func (e *ExpressionInterfaceImpl) AS(alias string) Projection {
|
||||
return newAlias(e.Parent, alias)
|
||||
}
|
||||
|
||||
// ASC expression will be used to sort query result in ascending order
|
||||
func (e *ExpressionInterfaceImpl) ASC() OrderByClause {
|
||||
return newOrderByClause(e.Parent, true)
|
||||
}
|
||||
|
||||
// DESC expression will be used to sort query result in ascending order
|
||||
func (e *ExpressionInterfaceImpl) DESC() OrderByClause {
|
||||
return newOrderByClause(e.Parent, false)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,17 @@
|
|||
package jet
|
||||
|
||||
// Interval is internal common representation of sql interval
|
||||
type Interval interface {
|
||||
Serializer
|
||||
IsInterval
|
||||
}
|
||||
|
||||
// IsInterval interface
|
||||
type IsInterval interface {
|
||||
isInterval()
|
||||
}
|
||||
|
||||
// NewInterval creates new interval from serializer
|
||||
func NewInterval(s Serializer) Interval {
|
||||
newInterval := &intervalImpl{
|
||||
interval: s,
|
||||
|
|
|
|||
|
|
@ -334,20 +334,20 @@ func WRAP(expression ...Expression) Expression {
|
|||
|
||||
//---------------------------------------------------//
|
||||
|
||||
type RawExpression struct {
|
||||
type rawExpression struct {
|
||||
ExpressionInterfaceImpl
|
||||
|
||||
Raw string
|
||||
}
|
||||
|
||||
func (n *RawExpression) serialize(statement StatementType, out *SQLBuilder, options ...SerializeOption) {
|
||||
func (n *rawExpression) serialize(statement StatementType, out *SQLBuilder, options ...SerializeOption) {
|
||||
out.WriteString(n.Raw)
|
||||
}
|
||||
|
||||
// Raw can be used for any unsupported functions, operators or expressions.
|
||||
// For example: Raw("current_database()")
|
||||
func Raw(raw string) Expression {
|
||||
rawExp := &RawExpression{Raw: raw}
|
||||
rawExp := &rawExpression{Raw: raw}
|
||||
rawExp.ExpressionInterfaceImpl.Parent = rawExp
|
||||
|
||||
return rawExp
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ func contains(options []SerializeOption, option SerializeOption) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// ListSerializer serializes list of serializers with separator
|
||||
type ListSerializer struct {
|
||||
Serializers []Serializer
|
||||
Separator string
|
||||
|
|
|
|||
|
|
@ -142,12 +142,8 @@ func argToString(value interface{}) string {
|
|||
return "TRUE"
|
||||
}
|
||||
return "FALSE"
|
||||
case int:
|
||||
return strconv.FormatInt(int64(bindVal), 10)
|
||||
case int32:
|
||||
return strconv.FormatInt(int64(bindVal), 10)
|
||||
case int64:
|
||||
return strconv.FormatInt(bindVal, 10)
|
||||
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
|
||||
return integerTypesToString(bindVal)
|
||||
|
||||
case float32:
|
||||
return strconv.FormatFloat(float64(bindVal), 'f', -1, 64)
|
||||
|
|
@ -167,6 +163,33 @@ func argToString(value interface{}) string {
|
|||
}
|
||||
}
|
||||
|
||||
func integerTypesToString(value interface{}) string {
|
||||
switch bindVal := value.(type) {
|
||||
case bool:
|
||||
case int:
|
||||
return strconv.FormatInt(int64(bindVal), 10)
|
||||
case uint:
|
||||
return strconv.FormatUint(uint64(bindVal), 10)
|
||||
case int8:
|
||||
return strconv.FormatInt(int64(bindVal), 10)
|
||||
case uint8:
|
||||
return strconv.FormatUint(uint64(bindVal), 10)
|
||||
case int16:
|
||||
return strconv.FormatInt(int64(bindVal), 10)
|
||||
case uint16:
|
||||
return strconv.FormatUint(uint64(bindVal), 10)
|
||||
case int32:
|
||||
return strconv.FormatInt(int64(bindVal), 10)
|
||||
case uint32:
|
||||
return strconv.FormatUint(uint64(bindVal), 10)
|
||||
case int64:
|
||||
return strconv.FormatInt(bindVal, 10)
|
||||
case uint64:
|
||||
return strconv.FormatUint(bindVal, 10)
|
||||
}
|
||||
panic("jet: Unsupported integer type: " + reflect.TypeOf(value).String())
|
||||
}
|
||||
|
||||
func shouldQuoteIdentifier(identifier string) bool {
|
||||
for _, c := range identifier {
|
||||
if unicode.IsNumber(c) || c == '_' {
|
||||
|
|
|
|||
|
|
@ -12,8 +12,16 @@ func TestArgToString(t *testing.T) {
|
|||
assert.Equal(t, argToString(false), "FALSE")
|
||||
|
||||
assert.Equal(t, argToString(int(-32)), "-32")
|
||||
assert.Equal(t, argToString(int32(-32)), "-32")
|
||||
assert.Equal(t, argToString(uint(32)), "32")
|
||||
assert.Equal(t, argToString(int8(-43)), "-43")
|
||||
assert.Equal(t, argToString(uint8(43)), "43")
|
||||
assert.Equal(t, argToString(int16(-54)), "-54")
|
||||
assert.Equal(t, argToString(uint16(54)), "54")
|
||||
assert.Equal(t, argToString(int32(-65)), "-65")
|
||||
assert.Equal(t, argToString(uint32(65)), "65")
|
||||
assert.Equal(t, argToString(int64(-64)), "-64")
|
||||
assert.Equal(t, argToString(uint64(64)), "64")
|
||||
assert.Equal(t, argToString(float32(2.0)), "2")
|
||||
assert.Equal(t, argToString(float64(1.11)), "1.11")
|
||||
|
||||
assert.Equal(t, argToString("john"), "'john'")
|
||||
|
|
@ -63,6 +63,7 @@ func SerializeColumnNames(columns []Column, out *SQLBuilder) {
|
|||
}
|
||||
}
|
||||
|
||||
// ExpressionListToSerializerList converts list of expressions to list of serializers
|
||||
func ExpressionListToSerializerList(expressions []Expression) []Serializer {
|
||||
var ret []Serializer
|
||||
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ func AssertClauseSerialize(t *testing.T, dialect jet.Dialect, clause jet.Seriali
|
|||
}
|
||||
}
|
||||
|
||||
// AssertClauseSerialize checks if clause serialize produces expected query and args
|
||||
// AssertDebugClauseSerialize checks if clause serialize produces expected debug query and args
|
||||
func AssertDebugClauseSerialize(t *testing.T, dialect jet.Dialect, clause jet.Serializer, query string, args ...interface{}) {
|
||||
out := jet.SQLBuilder{Dialect: dialect, Debug: true}
|
||||
jet.Serialize(clause, jet.SelectStatementType, &out)
|
||||
|
|
|
|||
|
|
@ -184,6 +184,7 @@ func StringSliceContains(strings []string, contains string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// ExtractDateTimeComponents extracts number of days, hours, minutes, seconds, microseconds from duration
|
||||
func ExtractDateTimeComponents(duration time.Duration) (days, hours, minutes, seconds, microseconds int64) {
|
||||
days = int64(duration / (24 * time.Hour))
|
||||
reminder := duration % (24 * time.Hour)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue