Remove unused cast interface.

This commit is contained in:
go-jet 2024-11-01 12:30:37 +01:00
parent aaf705d770
commit 4f0832b0e7
3 changed files with 79 additions and 142 deletions

View file

@ -5,66 +5,40 @@ import (
"strconv" "strconv"
) )
type cast interface { type cast struct {
// AS casts expressions as castType type
AS(castType string) Expression
// AS_CHAR casts expression as char with optional length
AS_CHAR(length ...int) StringExpression
// AS_DATE casts expression AS date type
AS_DATE() DateExpression
// AS_FLOAT casts expressions as float type
AS_FLOAT() FloatExpression
// AS_DOUBLE casts expressions as double type
AS_DOUBLE() FloatExpression
// AS_DECIMAL casts expression AS numeric type
AS_DECIMAL() FloatExpression
// AS_TIME casts expression AS time type
AS_TIME() TimeExpression
// AS_DATETIME casts expression as datetime type
AS_DATETIME() DateTimeExpression
// AS_SIGNED casts expressions as signed integer type
AS_SIGNED() IntegerExpression
// AS_UNSIGNED casts expression as unsigned integer type
AS_UNSIGNED() IntegerExpression
// AS_BINARY casts expression as binary type
AS_BINARY() StringExpression
}
type castImpl struct {
jet.Cast jet.Cast
} }
// CAST function converts a expr (of any type) into latter specified datatype. // CAST function converts a expr (of any type) into latter specified datatype.
func CAST(expr Expression) cast { func CAST(expr Expression) *cast {
castImpl := &castImpl{} ret := &cast{}
ret.Cast = jet.NewCastImpl(expr)
castImpl.Cast = jet.NewCastImpl(expr) return ret
return castImpl
} }
// AS casts expressions to castType // AS casts expressions to castType
func (c *castImpl) AS(castType string) Expression { func (c *cast) AS(castType string) Expression {
return c.Cast.AS(castType) return c.Cast.AS(castType)
} }
// AS_DATETIME cast expression to DATETIME type // AS_DATETIME cast expression to DATETIME type
func (c *castImpl) AS_DATETIME() DateTimeExpression { func (c *cast) AS_DATETIME() DateTimeExpression {
return DateTimeExp(c.AS("DATETIME")) return DateTimeExp(c.AS("DATETIME"))
} }
// AS_SIGNED casts expression to SIGNED type // AS_SIGNED casts expression to SIGNED type
func (c *castImpl) AS_SIGNED() IntegerExpression { func (c *cast) AS_SIGNED() IntegerExpression {
return IntExp(c.AS("SIGNED")) return IntExp(c.AS("SIGNED"))
} }
// AS_UNSIGNED casts expression to UNSIGNED type // AS_UNSIGNED casts expression to UNSIGNED type
func (c *castImpl) AS_UNSIGNED() IntegerExpression { func (c *cast) AS_UNSIGNED() IntegerExpression {
return IntExp(c.AS("UNSIGNED")) return IntExp(c.AS("UNSIGNED"))
} }
// AS_CHAR casts expression to CHAR type with optional length // AS_CHAR casts expression to CHAR type with optional length
func (c *castImpl) AS_CHAR(length ...int) StringExpression { func (c *cast) AS_CHAR(length ...int) StringExpression {
if len(length) > 0 { if len(length) > 0 {
return StringExp(c.AS("CHAR(" + strconv.Itoa(length[0]) + ")")) return StringExp(c.AS("CHAR(" + strconv.Itoa(length[0]) + ")"))
} }
@ -73,29 +47,29 @@ func (c *castImpl) AS_CHAR(length ...int) StringExpression {
} }
// AS_DATE casts expression AS DATE type // AS_DATE casts expression AS DATE type
func (c *castImpl) AS_DATE() DateExpression { func (c *cast) AS_DATE() DateExpression {
return DateExp(c.AS("DATE")) return DateExp(c.AS("DATE"))
} }
func (c *castImpl) AS_FLOAT() FloatExpression { func (c *cast) AS_FLOAT() FloatExpression {
return FloatExp(c.AS("FLOAT")) return FloatExp(c.AS("FLOAT"))
} }
func (c *castImpl) AS_DOUBLE() FloatExpression { func (c *cast) AS_DOUBLE() FloatExpression {
return FloatExp(c.AS("DOUBLE")) return FloatExp(c.AS("DOUBLE"))
} }
// AS_DECIMAL casts expression AS DECIMAL type // AS_DECIMAL casts expression AS DECIMAL type
func (c *castImpl) AS_DECIMAL() FloatExpression { func (c *cast) AS_DECIMAL() FloatExpression {
return FloatExp(c.AS("DECIMAL")) return FloatExp(c.AS("DECIMAL"))
} }
// AS_TIME casts expression AS TIME type // AS_TIME casts expression AS TIME type
func (c *castImpl) AS_TIME() TimeExpression { func (c *cast) AS_TIME() TimeExpression {
return TimeExp(c.AS("TIME")) return TimeExp(c.AS("TIME"))
} }
// AS_BINARY casts expression as BINARY type // AS_BINARY casts expression as BINARY type
func (c *castImpl) AS_BINARY() StringExpression { func (c *cast) AS_BINARY() StringExpression {
return StringExp(c.AS("BINARY")) return StringExp(c.AS("BINARY"))
} }

View file

@ -7,84 +7,45 @@ import (
"github.com/go-jet/jet/v2/internal/jet" "github.com/go-jet/jet/v2/internal/jet"
) )
type cast interface { type cast struct {
AS(castType string) Expression
// Cast expression AS bool type
AS_BOOL() BoolExpression
// Cast expression AS smallint type
AS_SMALLINT() IntegerExpression
// Cast expression AS integer type
AS_INTEGER() IntegerExpression
// Cast expression AS bigint type
AS_BIGINT() IntegerExpression
// Cast expression AS numeric type, using precision and optionally scale
AS_NUMERIC(precisionAndScale ...int) FloatExpression
// Cast expression AS real type
AS_REAL() FloatExpression
// Cast expression AS double precision type
AS_DOUBLE() FloatExpression
// Cast expression AS char with optional length
AS_CHAR(length ...int) StringExpression
// Cast expression AS date type
AS_DATE() DateExpression
// Cast expression AS numeric type, using precision and optionally scale
AS_DECIMAL() FloatExpression
// Cast expression AS time type
AS_TIME() TimeExpression
// Cast expression AS text type
AS_TEXT() StringExpression
// Cast expression AS bytea type
AS_BYTEA() StringExpression
// Cast expression AS time with time timezone type
AS_TIMEZ() TimezExpression
// Cast expression AS timestamp type
AS_TIMESTAMP() TimestampExpression
// Cast expression AS timestamp with timezone type
AS_TIMESTAMPZ() TimestampzExpression
// Cast expression AS interval type
AS_INTERVAL() IntervalExpression
}
type castImpl struct {
jet.Cast jet.Cast
} }
// CAST function converts a expr (of any type) into latter specified datatype. // CAST function converts an expr (of any type) into later specified datatype.
func CAST(expr Expression) cast { func CAST(expr Expression) *cast {
castImpl := &castImpl{} ret := &cast{}
ret.Cast = jet.NewCastImpl(expr)
castImpl.Cast = jet.NewCastImpl(expr) return ret
return castImpl
} }
// Cast expression as castType // AS casts expression as castType
func (b *castImpl) AS(castType string) Expression { func (b *cast) AS(castType string) Expression {
return b.Cast.AS(castType) return b.Cast.AS(castType)
} }
// Cast expression as bool type // AS_BOOL casts expression as bool type
func (b *castImpl) AS_BOOL() BoolExpression { func (b *cast) AS_BOOL() BoolExpression {
return BoolExp(b.AS("boolean")) return BoolExp(b.AS("boolean"))
} }
// Cast expression as smallint type // AS_SMALLINT casts expression as smallint type
func (b *castImpl) AS_SMALLINT() IntegerExpression { func (b *cast) AS_SMALLINT() IntegerExpression {
return IntExp(b.AS("smallint")) return IntExp(b.AS("smallint"))
} }
// Cast expression AS integer type // AS_INTEGER casts expression AS integer type
func (b *castImpl) AS_INTEGER() IntegerExpression { func (b *cast) AS_INTEGER() IntegerExpression {
return IntExp(b.AS("integer")) return IntExp(b.AS("integer"))
} }
// Cast expression AS bigint type // AS_BIGINT casts expression AS bigint type
func (b *castImpl) AS_BIGINT() IntegerExpression { func (b *cast) AS_BIGINT() IntegerExpression {
return IntExp(b.AS("bigint")) return IntExp(b.AS("bigint"))
} }
// Cast expression AS numeric type, using precision and optionally scale // AS_NUMERIC casts expression as numeric type, using precision and optionally scale
func (b *castImpl) AS_NUMERIC(precisionAndScale ...int) FloatExpression { func (b *cast) AS_NUMERIC(precisionAndScale ...int) FloatExpression {
var castArgs string var castArgs string
var argLen = len(precisionAndScale) var argLen = len(precisionAndScale)
@ -97,22 +58,23 @@ func (b *castImpl) AS_NUMERIC(precisionAndScale ...int) FloatExpression {
return FloatExp(b.AS("numeric" + castArgs)) return FloatExp(b.AS("numeric" + castArgs))
} }
// Cast expression AS real type // AS_REAL casts expression AS real type
func (b *castImpl) AS_REAL() FloatExpression { func (b *cast) AS_REAL() FloatExpression {
return FloatExp(b.AS("real")) return FloatExp(b.AS("real"))
} }
// Cast expression AS double precision type // AS_DOUBLE casts expression AS double precision type
func (b *castImpl) AS_DOUBLE() FloatExpression { func (b *cast) AS_DOUBLE() FloatExpression {
return FloatExp(b.AS("double precision")) return FloatExp(b.AS("double precision"))
} }
// Cast expression AS text type // AS_TEXT casts expression AS text type
func (b *castImpl) AS_TEXT() StringExpression { func (b *cast) AS_TEXT() StringExpression {
return StringExp(b.AS("text")) return StringExp(b.AS("text"))
} }
func (b *castImpl) AS_CHAR(length ...int) StringExpression { // AS_CHAR casts expression AS a character type
func (b *cast) AS_CHAR(length ...int) StringExpression {
if len(length) > 0 { if len(length) > 0 {
return StringExp(b.AS("char(" + strconv.Itoa(length[0]) + ")")) return StringExp(b.AS("char(" + strconv.Itoa(length[0]) + ")"))
} }
@ -120,42 +82,51 @@ func (b *castImpl) AS_CHAR(length ...int) StringExpression {
return StringExp(b.AS("char")) return StringExp(b.AS("char"))
} }
// Cast expression AS date type // AS_VARCHAR casts expression AS a character varying type
func (b *castImpl) AS_DATE() DateExpression { func (b *cast) AS_VARCHAR(length ...int) StringExpression {
if len(length) > 0 {
return StringExp(b.AS("varchar(" + strconv.Itoa(length[0]) + ")"))
}
return StringExp(b.AS("varchar"))
}
// AS_DATE casts expression AS date type
func (b *cast) AS_DATE() DateExpression {
return DateExp(b.AS("date")) return DateExp(b.AS("date"))
} }
// Cast expression AS date type // AS_DECIMAL casts expression AS date type
func (b *castImpl) AS_DECIMAL() FloatExpression { func (b *cast) AS_DECIMAL() FloatExpression {
return FloatExp(b.AS("decimal")) return FloatExp(b.AS("decimal"))
} }
// Cast expression AS text type // AS_BYTEA casts expression AS text type
func (b *castImpl) AS_BYTEA() StringExpression { func (b *cast) AS_BYTEA() StringExpression {
return StringExp(b.AS("bytea")) return StringExp(b.AS("bytea"))
} }
// Cast expression AS date type // AS_TIME casts expression AS date type
func (b *castImpl) AS_TIME() TimeExpression { func (b *cast) AS_TIME() TimeExpression {
return TimeExp(b.AS("time without time zone")) return TimeExp(b.AS("time without time zone"))
} }
// Cast expression AS time with time timezone type // AS_TIMEZ casts expression AS time with time timezone type
func (b *castImpl) AS_TIMEZ() TimezExpression { func (b *cast) AS_TIMEZ() TimezExpression {
return TimezExp(b.AS("time with time zone")) return TimezExp(b.AS("time with time zone"))
} }
// Cast expression AS timestamp type // AS_TIMESTAMP casts expression AS timestamp type
func (b *castImpl) AS_TIMESTAMP() TimestampExpression { func (b *cast) AS_TIMESTAMP() TimestampExpression {
return TimestampExp(b.AS("timestamp without time zone")) return TimestampExp(b.AS("timestamp without time zone"))
} }
// Cast expression AS timestamp with timezone type // AS_TIMESTAMPZ casts expression AS timestamp with timezone type
func (b *castImpl) AS_TIMESTAMPZ() TimestampzExpression { func (b *cast) AS_TIMESTAMPZ() TimestampzExpression {
return TimestampzExp(b.AS("timestamp with time zone")) return TimestampzExp(b.AS("timestamp with time zone"))
} }
// Cast expression AS interval type // AS_INTERVAL casts expression AS interval type
func (b *castImpl) AS_INTERVAL() IntervalExpression { func (b *cast) AS_INTERVAL() IntervalExpression {
return IntervalExp(b.AS("interval")) return IntervalExp(b.AS("interval"))
} }

View file

@ -4,52 +4,44 @@ import (
"github.com/go-jet/jet/v2/internal/jet" "github.com/go-jet/jet/v2/internal/jet"
) )
type cast interface { type cast struct {
AS(castType string) Expression
AS_TEXT() StringExpression
AS_NUMERIC() FloatExpression
AS_INTEGER() IntegerExpression
AS_REAL() FloatExpression
AS_BLOB() StringExpression
}
type castImpl struct {
jet.Cast jet.Cast
} }
// CAST function converts a expr (of any type) into latter specified datatype. // CAST function converts a expr (of any type) into latter specified datatype.
func CAST(expr Expression) cast { func CAST(expr Expression) *cast {
castImpl := &castImpl{} ret := &cast{}
castImpl.Cast = jet.NewCastImpl(expr) ret.Cast = jet.NewCastImpl(expr)
return castImpl
return ret
} }
// AS casts expressions to castType // AS casts expressions to castType
func (c *castImpl) AS(castType string) Expression { func (c *cast) AS(castType string) Expression {
return c.Cast.AS(castType) return c.Cast.AS(castType)
} }
// AS_TEXT cast expression to TEXT type // AS_TEXT cast expression to TEXT type
func (c *castImpl) AS_TEXT() StringExpression { func (c *cast) AS_TEXT() StringExpression {
return StringExp(c.AS("TEXT")) return StringExp(c.AS("TEXT"))
} }
// AS_NUMERIC cast expression to NUMERIC type // AS_NUMERIC cast expression to NUMERIC type
func (c *castImpl) AS_NUMERIC() FloatExpression { func (c *cast) AS_NUMERIC() FloatExpression {
return FloatExp(c.AS("NUMERIC")) return FloatExp(c.AS("NUMERIC"))
} }
// AS_INTEGER cast expression to INTEGER type // AS_INTEGER cast expression to INTEGER type
func (c *castImpl) AS_INTEGER() IntegerExpression { func (c *cast) AS_INTEGER() IntegerExpression {
return IntExp(c.AS("INTEGER")) return IntExp(c.AS("INTEGER"))
} }
// AS_REAL cast expression to REAL type // AS_REAL cast expression to REAL type
func (c *castImpl) AS_REAL() FloatExpression { func (c *cast) AS_REAL() FloatExpression {
return FloatExp(c.AS("REAL")) return FloatExp(c.AS("REAL"))
} }
// AS_BLOB cast expression to BLOB type // AS_BLOB cast expression to BLOB type
func (c *castImpl) AS_BLOB() StringExpression { func (c *cast) AS_BLOB() StringExpression {
return StringExp(c.AS("BLOB")) return StringExp(c.AS("BLOB"))
} }