Postgres linter errors.
This commit is contained in:
parent
46a3dc7dfb
commit
ab6d85f886
20 changed files with 310 additions and 29 deletions
|
|
@ -16,16 +16,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Host = "localhost"
|
host = "localhost"
|
||||||
Port = 5432
|
port = 5432
|
||||||
User = "jet"
|
user = "jet"
|
||||||
Password = "jet"
|
password = "jet"
|
||||||
DBName = "jetdb"
|
dbName = "jetdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Connect to database
|
// Connect to database
|
||||||
var connectString = fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", Host, Port, User, Password, DBName)
|
var connectString = fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", host, port, user, password, dbName)
|
||||||
|
|
||||||
db, err := sql.Open("postgres", connectString)
|
db, err := sql.Open("postgres", connectString)
|
||||||
panicOnError(err)
|
panicOnError(err)
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,8 @@ func (c columnImpl) serialize(statement StatementType, out *SqlBuilder, options
|
||||||
|
|
||||||
//------------------------------------------------------//
|
//------------------------------------------------------//
|
||||||
|
|
||||||
|
// IColumnList is used to store list of columns for later reuse as single projection or
|
||||||
|
// column list for UPDATE and INSERT statement.
|
||||||
type IColumnList interface {
|
type IColumnList interface {
|
||||||
Projection
|
Projection
|
||||||
Column
|
Column
|
||||||
|
|
@ -105,6 +107,7 @@ type IColumnList interface {
|
||||||
columns() []ColumnExpression
|
columns() []ColumnExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ColumnList function returns list of columns that be used as projection or column list for UPDATE and INSERT statement.
|
||||||
func ColumnList(columns ...ColumnExpression) IColumnList {
|
func ColumnList(columns ...ColumnExpression) IColumnList {
|
||||||
return columnListImpl(columns)
|
return columnListImpl(columns)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package jet
|
package jet
|
||||||
|
|
||||||
// DateExpression is interface for all SQL date expressions.
|
// DateExpression is interface for date types
|
||||||
type DateExpression interface {
|
type DateExpression interface {
|
||||||
Expression
|
Expression
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ type integerLiteralExpression struct {
|
||||||
integerInterfaceImpl
|
integerInterfaceImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
// Int is constructor for integer expressions literals.
|
// Int creates new integer literal
|
||||||
func Int(value int64) IntegerExpression {
|
func Int(value int64) IntegerExpression {
|
||||||
numLiteral := &integerLiteralExpression{}
|
numLiteral := &integerLiteralExpression{}
|
||||||
|
|
||||||
|
|
@ -94,7 +94,7 @@ type floatLiteral struct {
|
||||||
literalExpressionImpl
|
literalExpressionImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
// Float creates new float literal expression
|
// Float creates new float literal
|
||||||
func Float(value float64) FloatExpression {
|
func Float(value float64) FloatExpression {
|
||||||
floatLiteral := floatLiteral{}
|
floatLiteral := floatLiteral{}
|
||||||
floatLiteral.literalExpressionImpl = *literal(value)
|
floatLiteral.literalExpressionImpl = *literal(value)
|
||||||
|
|
@ -139,6 +139,7 @@ func Time(hour, minute, second int, nanoseconds ...time.Duration) TimeExpression
|
||||||
return timeLiteral
|
return timeLiteral
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TimeT creates new time literal expression from time.Time object
|
||||||
func TimeT(t time.Time) TimeExpression {
|
func TimeT(t time.Time) TimeExpression {
|
||||||
timeLiteral := &timeLiteral{}
|
timeLiteral := &timeLiteral{}
|
||||||
timeLiteral.literalExpressionImpl = *literal(t)
|
timeLiteral.literalExpressionImpl = *literal(t)
|
||||||
|
|
@ -165,6 +166,7 @@ func Timez(hour, minute, second int, nanoseconds time.Duration, timezone string)
|
||||||
return TimezExp(literal(timeStr))
|
return TimezExp(literal(timeStr))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TimezT creates new time with time zone literal expression from time.Time object
|
||||||
func TimezT(t time.Time) TimezExpression {
|
func TimezT(t time.Time) TimezExpression {
|
||||||
timeLiteral := &timezLiteral{}
|
timeLiteral := &timezLiteral{}
|
||||||
timeLiteral.literalExpressionImpl = *literal(t)
|
timeLiteral.literalExpressionImpl = *literal(t)
|
||||||
|
|
@ -190,6 +192,7 @@ func Timestamp(year int, month time.Month, day, hour, minute, second int, nanose
|
||||||
return timestamp
|
return timestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TimestampT creates new timestamp literal expression from time.Time object
|
||||||
func TimestampT(t time.Time) TimestampExpression {
|
func TimestampT(t time.Time) TimestampExpression {
|
||||||
timestamp := ×tampLiteral{}
|
timestamp := ×tampLiteral{}
|
||||||
timestamp.literalExpressionImpl = *literal(t)
|
timestamp.literalExpressionImpl = *literal(t)
|
||||||
|
|
@ -204,7 +207,7 @@ type timestampzLiteral struct {
|
||||||
literalExpressionImpl
|
literalExpressionImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
// Timestamp creates new timestamp literal expression
|
// Timestampz creates new timestamp with time zone literal expression
|
||||||
func Timestampz(year int, month time.Month, day, hour, minute, second int, nanoseconds time.Duration, timezone string) TimestampzExpression {
|
func Timestampz(year int, month time.Month, day, hour, minute, second int, nanoseconds time.Duration, timezone string) TimestampzExpression {
|
||||||
timestamp := ×tampzLiteral{}
|
timestamp := ×tampzLiteral{}
|
||||||
timeStr := fmt.Sprintf("%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second)
|
timeStr := fmt.Sprintf("%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second)
|
||||||
|
|
@ -216,6 +219,7 @@ func Timestampz(year int, month time.Month, day, hour, minute, second int, nanos
|
||||||
return timestamp
|
return timestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TimestampzT creates new timestamp literal expression from time.Time object
|
||||||
func TimestampzT(t time.Time) TimestampzExpression {
|
func TimestampzT(t time.Time) TimestampzExpression {
|
||||||
timestamp := ×tampzLiteral{}
|
timestamp := ×tampzLiteral{}
|
||||||
timestamp.literalExpressionImpl = *literal(t)
|
timestamp.literalExpressionImpl = *literal(t)
|
||||||
|
|
@ -230,7 +234,7 @@ type dateLiteral struct {
|
||||||
literalExpressionImpl
|
literalExpressionImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
//Date creates new date expression
|
// Date creates new date literal expression
|
||||||
func Date(year int, month time.Month, day int) DateExpression {
|
func Date(year int, month time.Month, day int) DateExpression {
|
||||||
dateLiteral := &dateLiteral{}
|
dateLiteral := &dateLiteral{}
|
||||||
|
|
||||||
|
|
@ -241,6 +245,7 @@ func Date(year int, month time.Month, day int) DateExpression {
|
||||||
return dateLiteral
|
return dateLiteral
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DateT creates new date literal expression from time.Time object
|
||||||
func DateT(t time.Time) DateExpression {
|
func DateT(t time.Time) DateExpression {
|
||||||
dateLiteral := &dateLiteral{}
|
dateLiteral := &dateLiteral{}
|
||||||
dateLiteral.literalExpressionImpl = *literal(t)
|
dateLiteral.literalExpressionImpl = *literal(t)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package jet
|
package jet
|
||||||
|
|
||||||
// TimezExpression interface 'time with time zone'
|
// TimezExpression interface for 'time with time zone' types
|
||||||
type TimezExpression interface {
|
type TimezExpression interface {
|
||||||
Expression
|
Expression
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ type castImpl struct {
|
||||||
jet.Cast
|
jet.Cast
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CAST function converts a expr (of any type) into latter specified datatype.
|
||||||
func CAST(expr Expression) cast {
|
func CAST(expr Expression) cast {
|
||||||
castImpl := &castImpl{}
|
castImpl := &castImpl{}
|
||||||
|
|
||||||
|
|
@ -54,14 +55,17 @@ func CAST(expr Expression) cast {
|
||||||
return castImpl
|
return castImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cast expression as castType
|
||||||
func (b *castImpl) AS(castType string) Expression {
|
func (b *castImpl) AS(castType string) Expression {
|
||||||
return b.Cast.AS(castType)
|
return b.Cast.AS(castType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cast expression as bool type
|
||||||
func (b *castImpl) AS_BOOL() BoolExpression {
|
func (b *castImpl) AS_BOOL() BoolExpression {
|
||||||
return BoolExp(b.AS("boolean"))
|
return BoolExp(b.AS("boolean"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cast expression as smallint type
|
||||||
func (b *castImpl) AS_SMALLINT() IntegerExpression {
|
func (b *castImpl) AS_SMALLINT() IntegerExpression {
|
||||||
return IntExp(b.AS("smallint"))
|
return IntExp(b.AS("smallint"))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@ import (
|
||||||
"github.com/go-jet/jet/internal/jet"
|
"github.com/go-jet/jet/internal/jet"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ClauseReturning struct {
|
type clauseReturning struct {
|
||||||
Projections []jet.Projection
|
Projections []jet.Projection
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ClauseReturning) Serialize(statementType jet.StatementType, out *jet.SqlBuilder) {
|
func (r *clauseReturning) Serialize(statementType jet.StatementType, out *jet.SqlBuilder) {
|
||||||
if len(r.Projections) == 0 {
|
if len(r.Projections) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,44 +2,67 @@ package postgres
|
||||||
|
|
||||||
import "github.com/go-jet/jet/internal/jet"
|
import "github.com/go-jet/jet/internal/jet"
|
||||||
|
|
||||||
|
// Column is common column interface for all types of columns.
|
||||||
type Column jet.ColumnExpression
|
type Column jet.ColumnExpression
|
||||||
|
|
||||||
|
// IColumnList is used to store list of columns for later reuse as single projection or
|
||||||
|
// column list for UPDATE and INSERT statement.
|
||||||
type IColumnList jet.IColumnList
|
type IColumnList jet.IColumnList
|
||||||
|
|
||||||
|
// ColumnList function returns list of columns that be used as projection or column list for UPDATE and INSERT statement.
|
||||||
var ColumnList = jet.ColumnList
|
var ColumnList = jet.ColumnList
|
||||||
|
|
||||||
|
// ColumnBool is interface for SQL boolean columns.
|
||||||
type ColumnBool jet.ColumnBool
|
type ColumnBool jet.ColumnBool
|
||||||
|
|
||||||
|
// BoolColumn creates named bool column.
|
||||||
var BoolColumn = jet.BoolColumn
|
var BoolColumn = jet.BoolColumn
|
||||||
|
|
||||||
|
// ColumnString is interface for SQL text, character, character varying
|
||||||
|
// bytea, uuid columns and enums types.
|
||||||
type ColumnString jet.ColumnString
|
type ColumnString jet.ColumnString
|
||||||
|
|
||||||
|
// StringColumn creates named string column.
|
||||||
var StringColumn = jet.StringColumn
|
var StringColumn = jet.StringColumn
|
||||||
|
|
||||||
|
// ColumnInteger is interface for SQL smallint, integer, bigint columns.
|
||||||
type ColumnInteger jet.ColumnInteger
|
type ColumnInteger jet.ColumnInteger
|
||||||
|
|
||||||
|
// IntegerColumn creates named integer column.
|
||||||
var IntegerColumn = jet.IntegerColumn
|
var IntegerColumn = jet.IntegerColumn
|
||||||
|
|
||||||
|
// ColumnFloat is interface for SQL real, numeric, decimal or double precision column.
|
||||||
type ColumnFloat jet.ColumnFloat
|
type ColumnFloat jet.ColumnFloat
|
||||||
|
|
||||||
|
// FloatColumn creates named float column.
|
||||||
var FloatColumn = jet.FloatColumn
|
var FloatColumn = jet.FloatColumn
|
||||||
|
|
||||||
|
// ColumnDate is interface of SQL date columns.
|
||||||
type ColumnDate jet.ColumnDate
|
type ColumnDate jet.ColumnDate
|
||||||
|
|
||||||
|
// DateColumn creates named date column.
|
||||||
var DateColumn = jet.DateColumn
|
var DateColumn = jet.DateColumn
|
||||||
|
|
||||||
|
// ColumnTime is interface for SQL time column.
|
||||||
type ColumnTime jet.ColumnTime
|
type ColumnTime jet.ColumnTime
|
||||||
|
|
||||||
|
// TimeColumn creates named time column
|
||||||
var TimeColumn = jet.TimeColumn
|
var TimeColumn = jet.TimeColumn
|
||||||
|
|
||||||
|
// ColumnTimez is interface of SQL time with time zone columns.
|
||||||
type ColumnTimez jet.ColumnTimez
|
type ColumnTimez jet.ColumnTimez
|
||||||
|
|
||||||
|
// TimezColumn creates named time with time zone column.
|
||||||
var TimezColumn = jet.TimezColumn
|
var TimezColumn = jet.TimezColumn
|
||||||
|
|
||||||
|
// ColumnTimestamp is interface of SQL timestamp columns.
|
||||||
type ColumnTimestamp jet.ColumnTimestamp
|
type ColumnTimestamp jet.ColumnTimestamp
|
||||||
|
|
||||||
|
// TimestampColumn creates named timestamp column
|
||||||
var TimestampColumn = jet.TimestampColumn
|
var TimestampColumn = jet.TimestampColumn
|
||||||
|
|
||||||
|
// ColumnTimestampz is interface of SQL timestamp with timezone columns.
|
||||||
type ColumnTimestampz jet.ColumnTimestampz
|
type ColumnTimestampz jet.ColumnTimestampz
|
||||||
|
|
||||||
|
// TimestampzColumn creates named timestamp with time zone column.
|
||||||
var TimestampzColumn = jet.TimestampzColumn
|
var TimestampzColumn = jet.TimestampzColumn
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package postgres
|
||||||
|
|
||||||
import "github.com/go-jet/jet/internal/jet"
|
import "github.com/go-jet/jet/internal/jet"
|
||||||
|
|
||||||
|
// DeleteStatement is interface for PostgreSQL DELETE statement
|
||||||
type DeleteStatement interface {
|
type DeleteStatement interface {
|
||||||
Statement
|
Statement
|
||||||
|
|
||||||
|
|
@ -15,7 +16,7 @@ type deleteStatementImpl struct {
|
||||||
|
|
||||||
Delete jet.ClauseStatementBegin
|
Delete jet.ClauseStatementBegin
|
||||||
Where jet.ClauseWhere
|
Where jet.ClauseWhere
|
||||||
Returning ClauseReturning
|
Returning clauseReturning
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDeleteStatement(table WritableTable) DeleteStatement {
|
func newDeleteStatement(table WritableTable) DeleteStatement {
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,10 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Dialect = NewDialect()
|
// Dialect is implementation of postgres dialect for SQL Builder serialisation.
|
||||||
|
var Dialect = newDialect()
|
||||||
|
|
||||||
func NewDialect() jet.Dialect {
|
func newDialect() jet.Dialect {
|
||||||
|
|
||||||
operatorSerializeOverrides := map[string]jet.SerializeOverride{}
|
operatorSerializeOverrides := map[string]jet.SerializeOverride{}
|
||||||
operatorSerializeOverrides[jet.StringRegexpLikeOperator] = postgres_REGEXP_LIKE_operator
|
operatorSerializeOverrides[jet.StringRegexpLikeOperator] = postgres_REGEXP_LIKE_operator
|
||||||
|
|
|
||||||
|
|
@ -2,36 +2,85 @@ package postgres
|
||||||
|
|
||||||
import "github.com/go-jet/jet/internal/jet"
|
import "github.com/go-jet/jet/internal/jet"
|
||||||
|
|
||||||
|
// Expression is common interface for all expressions.
|
||||||
|
// Can be Bool, Int, Float, String, Date, Time, Timez, Timestamp or Timestampz expressions.
|
||||||
type Expression jet.Expression
|
type Expression jet.Expression
|
||||||
|
|
||||||
|
// BoolExpression interface
|
||||||
type BoolExpression jet.BoolExpression
|
type BoolExpression jet.BoolExpression
|
||||||
|
|
||||||
|
// StringExpression interface
|
||||||
type StringExpression jet.StringExpression
|
type StringExpression jet.StringExpression
|
||||||
|
|
||||||
|
// IntegerExpression interface
|
||||||
type IntegerExpression jet.IntegerExpression
|
type IntegerExpression jet.IntegerExpression
|
||||||
|
|
||||||
|
//FloatExpression is interface
|
||||||
type FloatExpression jet.FloatExpression
|
type FloatExpression jet.FloatExpression
|
||||||
|
|
||||||
|
// TimeExpression interface
|
||||||
type TimeExpression jet.TimeExpression
|
type TimeExpression jet.TimeExpression
|
||||||
|
|
||||||
|
// TimezExpression interface for 'time with time zone' types
|
||||||
type TimezExpression jet.TimezExpression
|
type TimezExpression jet.TimezExpression
|
||||||
|
|
||||||
|
// DateExpression is interface for date types
|
||||||
type DateExpression jet.DateExpression
|
type DateExpression jet.DateExpression
|
||||||
|
|
||||||
|
// TimestampExpression interface
|
||||||
type TimestampExpression jet.TimestampExpression
|
type TimestampExpression jet.TimestampExpression
|
||||||
|
|
||||||
|
// TimestampzExpression interface
|
||||||
type TimestampzExpression jet.TimestampzExpression
|
type TimestampzExpression jet.TimestampzExpression
|
||||||
|
|
||||||
|
// BoolExp is bool expression wrapper around arbitrary expression.
|
||||||
|
// Allows go compiler to see any expression as bool expression.
|
||||||
|
// Does not add sql cast to generated sql builder output.
|
||||||
var BoolExp = jet.BoolExp
|
var BoolExp = jet.BoolExp
|
||||||
|
|
||||||
|
// IntExp is int expression wrapper around arbitrary expression.
|
||||||
|
// Allows go compiler to see any expression as int expression.
|
||||||
|
// Does not add sql cast to generated sql builder output.
|
||||||
var IntExp = jet.IntExp
|
var IntExp = jet.IntExp
|
||||||
|
|
||||||
|
// FloatExp is date expression wrapper around arbitrary expression.
|
||||||
|
// Allows go compiler to see any expression as float expression.
|
||||||
|
// Does not add sql cast to generated sql builder output.
|
||||||
var FloatExp = jet.FloatExp
|
var FloatExp = jet.FloatExp
|
||||||
|
|
||||||
|
// TimeExp is time expression wrapper around arbitrary expression.
|
||||||
|
// Allows go compiler to see any expression as time expression.
|
||||||
|
// Does not add sql cast to generated sql builder output.
|
||||||
var TimeExp = jet.TimeExp
|
var TimeExp = jet.TimeExp
|
||||||
|
|
||||||
|
// StringExp is string expression wrapper around arbitrary expression.
|
||||||
|
// Allows go compiler to see any expression as string expression.
|
||||||
|
// Does not add sql cast to generated sql builder output.
|
||||||
var StringExp = jet.StringExp
|
var StringExp = jet.StringExp
|
||||||
|
|
||||||
|
// TimezExp is time with time zone expression wrapper around arbitrary expression.
|
||||||
|
// Allows go compiler to see any expression as time with time zone expression.
|
||||||
|
// Does not add sql cast to generated sql builder output.
|
||||||
var TimezExp = jet.TimezExp
|
var TimezExp = jet.TimezExp
|
||||||
|
|
||||||
|
// DateExp is date expression wrapper around arbitrary expression.
|
||||||
|
// Allows go compiler to see any expression as date expression.
|
||||||
|
// Does not add sql cast to generated sql builder output.
|
||||||
var DateExp = jet.DateExp
|
var DateExp = jet.DateExp
|
||||||
|
|
||||||
|
// TimestampExp is timestamp expression wrapper around arbitrary expression.
|
||||||
|
// Allows go compiler to see any expression as timestamp expression.
|
||||||
|
// Does not add sql cast to generated sql builder output.
|
||||||
var TimestampExp = jet.TimestampExp
|
var TimestampExp = jet.TimestampExp
|
||||||
|
|
||||||
|
// TimestampzExp is timestamp with time zone expression wrapper around arbitrary expression.
|
||||||
|
// Allows go compiler to see any expression as timestamp with time zone expression.
|
||||||
|
// Does not add sql cast to generated sql builder output.
|
||||||
var TimestampzExp = jet.TimestampzExp
|
var TimestampzExp = jet.TimestampzExp
|
||||||
|
|
||||||
|
// Raw can be used for any unsupported functions, operators or expressions.
|
||||||
|
// For example: Raw("current_database()")
|
||||||
var Raw = jet.Raw
|
var Raw = jet.Raw
|
||||||
|
|
||||||
|
// NewEnumValue creates new named enum value
|
||||||
var NewEnumValue = jet.NewEnumValue
|
var NewEnumValue = jet.NewEnumValue
|
||||||
|
|
|
||||||
|
|
@ -2,108 +2,260 @@ package postgres
|
||||||
|
|
||||||
import "github.com/go-jet/jet/internal/jet"
|
import "github.com/go-jet/jet/internal/jet"
|
||||||
|
|
||||||
|
// ROW is construct one table row from list of expressions.
|
||||||
var ROW = jet.ROW
|
var ROW = jet.ROW
|
||||||
|
|
||||||
// ------------------ Mathematical functions ---------------//
|
// ------------------ Mathematical functions ---------------//
|
||||||
|
|
||||||
|
// ABSf calculates absolute value from float expression
|
||||||
var ABSf = jet.ABSf
|
var ABSf = jet.ABSf
|
||||||
|
|
||||||
|
// ABSi calculates absolute value from int expression
|
||||||
var ABSi = jet.ABSi
|
var ABSi = jet.ABSi
|
||||||
|
|
||||||
|
// POW calculates power of base with exponent
|
||||||
var POW = jet.POW
|
var POW = jet.POW
|
||||||
|
|
||||||
|
// POWER calculates power of base with exponent
|
||||||
var POWER = jet.POWER
|
var POWER = jet.POWER
|
||||||
|
|
||||||
|
// SQRT calculates square root of numeric expression
|
||||||
var SQRT = jet.SQRT
|
var SQRT = jet.SQRT
|
||||||
|
|
||||||
|
// CBRT calculates cube root of numeric expression
|
||||||
var CBRT = jet.CBRT
|
var CBRT = jet.CBRT
|
||||||
|
|
||||||
|
// CEIL calculates ceil of float expression
|
||||||
var CEIL = jet.CEIL
|
var CEIL = jet.CEIL
|
||||||
|
|
||||||
|
// FLOOR calculates floor of float expression
|
||||||
var FLOOR = jet.FLOOR
|
var FLOOR = jet.FLOOR
|
||||||
|
|
||||||
|
// ROUND calculates round of a float expressions with optional precision
|
||||||
var ROUND = jet.ROUND
|
var ROUND = jet.ROUND
|
||||||
|
|
||||||
|
// SIGN returns sign of float expression
|
||||||
var SIGN = jet.SIGN
|
var SIGN = jet.SIGN
|
||||||
|
|
||||||
|
// TRUNC calculates trunc of float expression with optional precision
|
||||||
var TRUNC = jet.TRUNC
|
var TRUNC = jet.TRUNC
|
||||||
|
|
||||||
|
// LN calculates natural algorithm of float expression
|
||||||
var LN = jet.LN
|
var LN = jet.LN
|
||||||
|
|
||||||
|
// LOG calculates logarithm of float expression
|
||||||
var LOG = jet.LOG
|
var LOG = jet.LOG
|
||||||
|
|
||||||
// ----------------- Aggregate functions -------------------//
|
// ----------------- Aggregate functions -------------------//
|
||||||
|
|
||||||
|
// AVG is aggregate function used to calculate avg value from numeric expression
|
||||||
var AVG = jet.AVG
|
var AVG = jet.AVG
|
||||||
|
|
||||||
|
// BIT_AND is aggregate function used to calculates the bitwise AND of all non-null input values, or null if none.
|
||||||
var BIT_AND = jet.BIT_AND
|
var BIT_AND = jet.BIT_AND
|
||||||
|
|
||||||
|
// BIT_OR is aggregate function used to calculates the bitwise OR of all non-null input values, or null if none.
|
||||||
var BIT_OR = jet.BIT_OR
|
var BIT_OR = jet.BIT_OR
|
||||||
|
|
||||||
|
// BOOL_AND is aggregate function. Returns true if all input values are true, otherwise false
|
||||||
var BOOL_AND = jet.BOOL_AND
|
var BOOL_AND = jet.BOOL_AND
|
||||||
|
|
||||||
|
// BOOL_OR is aggregate function. Returns true if at least one input value is true, otherwise false
|
||||||
var BOOL_OR = jet.BOOL_OR
|
var BOOL_OR = jet.BOOL_OR
|
||||||
|
|
||||||
|
// COUNT is aggregate function. Returns number of input rows for which the value of expression is not null.
|
||||||
var COUNT = jet.COUNT
|
var COUNT = jet.COUNT
|
||||||
|
|
||||||
|
// EVERY is aggregate function. Returns true if all input values are true, otherwise false
|
||||||
var EVERY = jet.EVERY
|
var EVERY = jet.EVERY
|
||||||
|
|
||||||
|
// MAXf is aggregate function. Returns maximum value of float expression across all input values
|
||||||
var MAXf = jet.MAXf
|
var MAXf = jet.MAXf
|
||||||
|
|
||||||
|
// MAXi is aggregate function. Returns maximum value of int expression across all input values
|
||||||
var MAXi = jet.MAXi
|
var MAXi = jet.MAXi
|
||||||
|
|
||||||
|
// MINf is aggregate function. Returns minimum value of float expression across all input values
|
||||||
var MINf = jet.MINf
|
var MINf = jet.MINf
|
||||||
|
|
||||||
|
// MINi is aggregate function. Returns minimum value of int expression across all input values
|
||||||
var MINi = jet.MINi
|
var MINi = jet.MINi
|
||||||
|
|
||||||
|
// SUMf is aggregate function. Returns sum of expression across all float expressions
|
||||||
var SUMf = jet.SUMf
|
var SUMf = jet.SUMf
|
||||||
|
|
||||||
|
// SUMi is aggregate function. Returns sum of expression across all integer expression.
|
||||||
var SUMi = jet.SUMi
|
var SUMi = jet.SUMi
|
||||||
|
|
||||||
//--------------------- String functions ------------------//
|
//--------------------- String functions ------------------//
|
||||||
|
|
||||||
|
// BIT_LENGTH returns number of bits in string expression
|
||||||
var BIT_LENGTH = jet.BIT_LENGTH
|
var BIT_LENGTH = jet.BIT_LENGTH
|
||||||
|
|
||||||
|
// CHAR_LENGTH returns number of characters in string expression
|
||||||
var CHAR_LENGTH = jet.CHAR_LENGTH
|
var CHAR_LENGTH = jet.CHAR_LENGTH
|
||||||
|
|
||||||
|
// OCTET_LENGTH returns number of bytes in string expression
|
||||||
var OCTET_LENGTH = jet.OCTET_LENGTH
|
var OCTET_LENGTH = jet.OCTET_LENGTH
|
||||||
|
|
||||||
|
// LOWER returns string expression in lower case
|
||||||
var LOWER = jet.LOWER
|
var LOWER = jet.LOWER
|
||||||
|
|
||||||
|
// UPPER returns string expression in upper case
|
||||||
var UPPER = jet.UPPER
|
var UPPER = jet.UPPER
|
||||||
|
|
||||||
|
// BTRIM removes the longest string consisting only of characters
|
||||||
|
// in characters (a space by default) from the start and end of string
|
||||||
var BTRIM = jet.BTRIM
|
var BTRIM = jet.BTRIM
|
||||||
|
|
||||||
|
// LTRIM removes the longest string containing only characters
|
||||||
|
// from characters (a space by default) from the start of string
|
||||||
var LTRIM = jet.LTRIM
|
var LTRIM = jet.LTRIM
|
||||||
|
|
||||||
|
// RTRIM removes the longest string containing only characters
|
||||||
|
// from characters (a space by default) from the end of string
|
||||||
var RTRIM = jet.RTRIM
|
var RTRIM = jet.RTRIM
|
||||||
|
|
||||||
|
// CHR returns character with the given code.
|
||||||
var CHR = jet.CHR
|
var CHR = jet.CHR
|
||||||
|
|
||||||
|
// CONCAT adds two or more expressions together
|
||||||
var CONCAT = func(expressions ...Expression) StringExpression {
|
var CONCAT = func(expressions ...Expression) StringExpression {
|
||||||
return jet.CONCAT(explicitLiteralCasts(expressions...)...)
|
return jet.CONCAT(explicitLiteralCasts(expressions...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CONCAT_WS adds two or more expressions together with a separator.
|
||||||
func CONCAT_WS(separator Expression, expressions ...Expression) StringExpression {
|
func CONCAT_WS(separator Expression, expressions ...Expression) StringExpression {
|
||||||
return jet.CONCAT_WS(explicitLiteralCast(separator), explicitLiteralCasts(expressions...)...)
|
return jet.CONCAT_WS(explicitLiteralCast(separator), explicitLiteralCasts(expressions...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CONVERT converts string to dest_encoding. The original encoding is
|
||||||
|
// specified by src_encoding. The string must be valid in this encoding.
|
||||||
var CONVERT = jet.CONVERT
|
var CONVERT = jet.CONVERT
|
||||||
|
|
||||||
|
// CONVERT_FROM converts string to the database encoding. The original
|
||||||
|
// encoding is specified by src_encoding. The string must be valid in this encoding.
|
||||||
var CONVERT_FROM = jet.CONVERT_FROM
|
var CONVERT_FROM = jet.CONVERT_FROM
|
||||||
|
|
||||||
|
// CONVERT_TO converts string to dest_encoding.
|
||||||
var CONVERT_TO = jet.CONVERT_TO
|
var CONVERT_TO = jet.CONVERT_TO
|
||||||
|
|
||||||
|
// ENCODE encodes binary data into a textual representation.
|
||||||
|
// Supported formats are: base64, hex, escape. escape converts zero bytes and
|
||||||
|
// high-bit-set bytes to octal sequences (\nnn) and doubles backslashes.
|
||||||
var ENCODE = jet.ENCODE
|
var ENCODE = jet.ENCODE
|
||||||
|
|
||||||
|
// DECODE decodes binary data from textual representation in string.
|
||||||
|
// Options for format are same as in encode.
|
||||||
var DECODE = jet.DECODE
|
var DECODE = jet.DECODE
|
||||||
|
|
||||||
|
// FORMAT formats a number to a format like "#,###,###.##", rounded to a specified number of decimal places, then it returns the result as a string.
|
||||||
func FORMAT(formatStr StringExpression, formatArgs ...Expression) StringExpression {
|
func FORMAT(formatStr StringExpression, formatArgs ...Expression) StringExpression {
|
||||||
return jet.FORMAT(formatStr, explicitLiteralCasts(formatArgs...)...)
|
return jet.FORMAT(formatStr, explicitLiteralCasts(formatArgs...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// INITCAP converts the first letter of each word to upper case
|
||||||
|
// and the rest to lower case. Words are sequences of alphanumeric
|
||||||
|
// characters separated by non-alphanumeric characters.
|
||||||
var INITCAP = jet.INITCAP
|
var INITCAP = jet.INITCAP
|
||||||
|
|
||||||
|
// LEFT returns first n characters in the string.
|
||||||
|
// When n is negative, return all but last |n| characters.
|
||||||
var LEFT = jet.LEFT
|
var LEFT = jet.LEFT
|
||||||
|
|
||||||
|
// RIGHT returns last n characters in the string.
|
||||||
|
// When n is negative, return all but first |n| characters.
|
||||||
var RIGHT = jet.RIGHT
|
var RIGHT = jet.RIGHT
|
||||||
|
|
||||||
|
// LENGTH returns number of characters in string with a given encoding
|
||||||
var LENGTH = jet.LENGTH
|
var LENGTH = jet.LENGTH
|
||||||
|
|
||||||
|
// LPAD fills up the string to length length by prepending the characters
|
||||||
|
// fill (a space by default). If the string is already longer than length
|
||||||
|
// then it is truncated (on the right).
|
||||||
var LPAD = jet.LPAD
|
var LPAD = jet.LPAD
|
||||||
|
|
||||||
|
// RPAD fills up the string to length length by appending the characters
|
||||||
|
// fill (a space by default). If the string is already longer than length then it is truncated.
|
||||||
var RPAD = jet.RPAD
|
var RPAD = jet.RPAD
|
||||||
|
|
||||||
|
// MD5 calculates the MD5 hash of string, returning the result in hexadecimal
|
||||||
var MD5 = jet.MD5
|
var MD5 = jet.MD5
|
||||||
|
|
||||||
|
// REPEAT repeats string the specified number of times
|
||||||
var REPEAT = jet.REPEAT
|
var REPEAT = jet.REPEAT
|
||||||
|
|
||||||
|
// REPLACE replaces all occurrences in string of substring from with substring to
|
||||||
var REPLACE = jet.REPLACE
|
var REPLACE = jet.REPLACE
|
||||||
|
|
||||||
|
// REVERSE returns reversed string.
|
||||||
var REVERSE = jet.REVERSE
|
var REVERSE = jet.REVERSE
|
||||||
|
|
||||||
|
// STRPOS returns location of specified substring (same as position(substring in string),
|
||||||
|
// but note the reversed argument order)
|
||||||
var STRPOS = jet.STRPOS
|
var STRPOS = jet.STRPOS
|
||||||
|
|
||||||
|
// SUBSTR extracts substring
|
||||||
var SUBSTR = jet.SUBSTR
|
var SUBSTR = jet.SUBSTR
|
||||||
|
|
||||||
|
// TO_ASCII convert string to ASCII from another encoding
|
||||||
var TO_ASCII = jet.TO_ASCII
|
var TO_ASCII = jet.TO_ASCII
|
||||||
|
|
||||||
|
// TO_HEX converts number to its equivalent hexadecimal representation
|
||||||
var TO_HEX = jet.TO_HEX
|
var TO_HEX = jet.TO_HEX
|
||||||
|
|
||||||
//----------Data Type Formatting Functions ----------------------//
|
//----------Data Type Formatting Functions ----------------------//
|
||||||
|
|
||||||
|
// TO_CHAR converts expression to string with format
|
||||||
var TO_CHAR = jet.TO_CHAR
|
var TO_CHAR = jet.TO_CHAR
|
||||||
|
|
||||||
|
// TO_DATE converts string to date using format
|
||||||
var TO_DATE = jet.TO_DATE
|
var TO_DATE = jet.TO_DATE
|
||||||
|
|
||||||
|
// TO_NUMBER converts string to numeric using format
|
||||||
var TO_NUMBER = jet.TO_NUMBER
|
var TO_NUMBER = jet.TO_NUMBER
|
||||||
|
|
||||||
|
// TO_TIMESTAMP converts string to time stamp with time zone using format
|
||||||
var TO_TIMESTAMP = jet.TO_TIMESTAMP
|
var TO_TIMESTAMP = jet.TO_TIMESTAMP
|
||||||
|
|
||||||
//----------------- Date/Time Functions and Operators ------------//
|
//----------------- Date/Time Functions and Operators ------------//
|
||||||
|
|
||||||
|
// CURRENT_DATE returns current date
|
||||||
var CURRENT_DATE = jet.CURRENT_DATE
|
var CURRENT_DATE = jet.CURRENT_DATE
|
||||||
|
|
||||||
|
// CURRENT_TIME returns current time with time zone
|
||||||
var CURRENT_TIME = jet.CURRENT_TIME
|
var CURRENT_TIME = jet.CURRENT_TIME
|
||||||
|
|
||||||
|
// CURRENT_TIMESTAMP returns current timestamp with time zone
|
||||||
var CURRENT_TIMESTAMP = jet.CURRENT_TIMESTAMP
|
var CURRENT_TIMESTAMP = jet.CURRENT_TIMESTAMP
|
||||||
|
|
||||||
|
// LOCALTIME returns local time of day using optional precision
|
||||||
var LOCALTIME = jet.LOCALTIME
|
var LOCALTIME = jet.LOCALTIME
|
||||||
|
|
||||||
|
// LOCALTIMESTAMP returns current date and time using optional precision
|
||||||
var LOCALTIMESTAMP = jet.LOCALTIMESTAMP
|
var LOCALTIMESTAMP = jet.LOCALTIMESTAMP
|
||||||
|
|
||||||
|
// NOW returns current date and time
|
||||||
var NOW = jet.NOW
|
var NOW = jet.NOW
|
||||||
|
|
||||||
// --------------- Conditional Expressions Functions -------------//
|
// --------------- Conditional Expressions Functions -------------//
|
||||||
|
|
||||||
|
// COALESCE function returns the first of its arguments that is not null.
|
||||||
var COALESCE = jet.COALESCE
|
var COALESCE = jet.COALESCE
|
||||||
|
|
||||||
|
// NULLIF function returns a null value if value1 equals value2; otherwise it returns value1.
|
||||||
var NULLIF = jet.NULLIF
|
var NULLIF = jet.NULLIF
|
||||||
|
|
||||||
|
// GREATEST selects the largest value from a list of expressions
|
||||||
var GREATEST = jet.GREATEST
|
var GREATEST = jet.GREATEST
|
||||||
|
|
||||||
|
// LEAST selects the smallest value from a list of expressions
|
||||||
var LEAST = jet.LEAST
|
var LEAST = jet.LEAST
|
||||||
|
|
||||||
|
// EXISTS checks for existence of the rows in subQuery
|
||||||
var EXISTS = jet.EXISTS
|
var EXISTS = jet.EXISTS
|
||||||
|
|
||||||
|
// CASE create CASE operator with optional list of expressions
|
||||||
var CASE = jet.CASE
|
var CASE = jet.CASE
|
||||||
|
|
||||||
func explicitLiteralCasts(expressions ...Expression) []jet.Expression {
|
func explicitLiteralCasts(expressions ...Expression) []jet.Expression {
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ type insertStatementImpl struct {
|
||||||
|
|
||||||
Insert jet.ClauseInsert
|
Insert jet.ClauseInsert
|
||||||
ValuesQuery jet.ClauseValuesQuery
|
ValuesQuery jet.ClauseValuesQuery
|
||||||
Returning ClauseReturning
|
Returning clauseReturning
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *insertStatementImpl) VALUES(value interface{}, values ...interface{}) InsertStatement {
|
func (i *insertStatementImpl) VALUES(value interface{}, values ...interface{}) InsertStatement {
|
||||||
|
|
|
||||||
|
|
@ -5,41 +5,69 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Bool creates new bool literal expression
|
||||||
var Bool = jet.Bool
|
var Bool = jet.Bool
|
||||||
|
|
||||||
|
// Int creates new integer literal expression
|
||||||
var Int = jet.Int
|
var Int = jet.Int
|
||||||
|
|
||||||
|
// Float creates new float literal expression
|
||||||
var Float = jet.Float
|
var Float = jet.Float
|
||||||
|
|
||||||
|
// String creates new string literal expression
|
||||||
var String = jet.String
|
var String = jet.String
|
||||||
|
|
||||||
|
// Bytea craates new bytea literal expression
|
||||||
var Bytea = func(value string) StringExpression {
|
var Bytea = func(value string) StringExpression {
|
||||||
return CAST(jet.String(value)).AS_BYTEA()
|
return CAST(jet.String(value)).AS_BYTEA()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Date creates new date literal expression
|
||||||
var Date = func(year int, month time.Month, day int) DateExpression {
|
var Date = func(year int, month time.Month, day int) DateExpression {
|
||||||
return CAST(jet.Date(year, month, day)).AS_DATE()
|
return CAST(jet.Date(year, month, day)).AS_DATE()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DateT creates new date literal expression from time.Time object
|
||||||
var DateT = func(t time.Time) DateExpression {
|
var DateT = func(t time.Time) DateExpression {
|
||||||
return CAST(jet.DateT(t)).AS_DATE()
|
return CAST(jet.DateT(t)).AS_DATE()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Time creates new time literal expression
|
||||||
var Time = func(hour, minute, second int, nanoseconds ...time.Duration) TimeExpression {
|
var Time = func(hour, minute, second int, nanoseconds ...time.Duration) TimeExpression {
|
||||||
return CAST(jet.Time(hour, minute, second, nanoseconds...)).AS_TIME()
|
return CAST(jet.Time(hour, minute, second, nanoseconds...)).AS_TIME()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TimeT creates new time literal expression from time.Time object
|
||||||
var TimeT = func(t time.Time) TimeExpression {
|
var TimeT = func(t time.Time) TimeExpression {
|
||||||
return CAST(jet.TimeT(t)).AS_TIME()
|
return CAST(jet.TimeT(t)).AS_TIME()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Timez creates new time with time zone literal expression
|
||||||
var Timez = func(hour, minute, second int, milliseconds time.Duration, timezone string) TimezExpression {
|
var Timez = func(hour, minute, second int, milliseconds time.Duration, timezone string) TimezExpression {
|
||||||
return CAST(jet.Timez(hour, minute, second, milliseconds, timezone)).AS_TIMEZ()
|
return CAST(jet.Timez(hour, minute, second, milliseconds, timezone)).AS_TIMEZ()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TimezT creates new time with time zone literal expression from time.Time object
|
||||||
var TimezT = func(t time.Time) TimezExpression {
|
var TimezT = func(t time.Time) TimezExpression {
|
||||||
return CAST(jet.TimezT(t)).AS_TIMEZ()
|
return CAST(jet.TimezT(t)).AS_TIMEZ()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Timestamp creates new timestamp literal expression
|
||||||
var Timestamp = func(year int, month time.Month, day, hour, minute, second int, milliseconds ...time.Duration) TimestampExpression {
|
var Timestamp = func(year int, month time.Month, day, hour, minute, second int, milliseconds ...time.Duration) TimestampExpression {
|
||||||
return CAST(jet.Timestamp(year, month, day, hour, minute, second, milliseconds...)).AS_TIMESTAMP()
|
return CAST(jet.Timestamp(year, month, day, hour, minute, second, milliseconds...)).AS_TIMESTAMP()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TimestampT creates new timestamp literal expression from time.Time object
|
||||||
var TimestampT = func(t time.Time) TimestampExpression {
|
var TimestampT = func(t time.Time) TimestampExpression {
|
||||||
return CAST(jet.TimestampzT(t)).AS_TIMESTAMP()
|
return CAST(jet.TimestampT(t)).AS_TIMESTAMP()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Timestampz creates new timestamp with time zone literal expression
|
||||||
var Timestampz = func(year int, month time.Month, day, hour, minute, second int, milliseconds time.Duration, timezone string) TimestampzExpression {
|
var Timestampz = func(year int, month time.Month, day, hour, minute, second int, milliseconds time.Duration, timezone string) TimestampzExpression {
|
||||||
return CAST(jet.Timestampz(year, month, day, hour, minute, second, milliseconds, timezone)).AS_TIMESTAMPZ()
|
return CAST(jet.Timestampz(year, month, day, hour, minute, second, milliseconds, timezone)).AS_TIMESTAMPZ()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TimestampzT creates new timestamp literal expression from time.Time object
|
||||||
var TimestampzT = func(t time.Time) TimestampzExpression {
|
var TimestampzT = func(t time.Time) TimestampzExpression {
|
||||||
return CAST(jet.TimestampzT(t)).AS_TIMESTAMPZ()
|
return CAST(jet.TimestampzT(t)).AS_TIMESTAMPZ()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package postgres
|
||||||
|
|
||||||
import "github.com/go-jet/jet/internal/jet"
|
import "github.com/go-jet/jet/internal/jet"
|
||||||
|
|
||||||
|
// TableLockMode is a type of possible SQL table lock
|
||||||
type TableLockMode string
|
type TableLockMode string
|
||||||
|
|
||||||
// Lock types for LockStatement.
|
// Lock types for LockStatement.
|
||||||
|
|
@ -16,6 +17,7 @@ const (
|
||||||
LOCK_ACCESS_EXCLUSIVE TableLockMode = "ACCESS EXCLUSIVE"
|
LOCK_ACCESS_EXCLUSIVE TableLockMode = "ACCESS EXCLUSIVE"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// LockStatement is interface for MySQL LOCK tables
|
||||||
type LockStatement interface {
|
type LockStatement interface {
|
||||||
Statement
|
Statement
|
||||||
|
|
||||||
|
|
@ -23,6 +25,7 @@ type LockStatement interface {
|
||||||
NOWAIT() LockStatement
|
NOWAIT() LockStatement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LOCK creates LockStatement from list of tables
|
||||||
func LOCK(tables ...jet.SerializerTable) LockStatement {
|
func LOCK(tables ...jet.SerializerTable) LockStatement {
|
||||||
newLock := &lockStatementImpl{}
|
newLock := &lockStatementImpl{}
|
||||||
newLock.StatementImpl = jet.NewStatementImpl(Dialect, jet.LockStatementType, newLock,
|
newLock.StatementImpl = jet.NewStatementImpl(Dialect, jet.LockStatementType, newLock,
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,8 @@ package postgres
|
||||||
|
|
||||||
import "github.com/go-jet/jet/internal/jet"
|
import "github.com/go-jet/jet/internal/jet"
|
||||||
|
|
||||||
|
// NOT returns negation of bool expression result
|
||||||
var NOT = jet.NOT
|
var NOT = jet.NOT
|
||||||
|
|
||||||
|
// BIT_NOT inverts every bit in integer expression result
|
||||||
var BIT_NOT = jet.BIT_NOT
|
var BIT_NOT = jet.BIT_NOT
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,10 @@ package postgres
|
||||||
|
|
||||||
import "github.com/go-jet/jet/internal/jet"
|
import "github.com/go-jet/jet/internal/jet"
|
||||||
|
|
||||||
|
// RowLock is interface for SELECT statement row lock types
|
||||||
type RowLock = jet.RowLock
|
type RowLock = jet.RowLock
|
||||||
|
|
||||||
|
// Row lock types
|
||||||
var (
|
var (
|
||||||
UPDATE = jet.NewSelectLock("UPDATE")
|
UPDATE = jet.NewSelectLock("UPDATE")
|
||||||
NO_KEY_UPDATE = jet.NewSelectLock("NO KEY UPDATE")
|
NO_KEY_UPDATE = jet.NewSelectLock("NO KEY UPDATE")
|
||||||
|
|
@ -11,6 +13,7 @@ var (
|
||||||
KEY_SHARE = jet.NewSelectLock("KEY SHARE")
|
KEY_SHARE = jet.NewSelectLock("KEY SHARE")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// SelectStatement is interface for PostgreSQL SELECT statement
|
||||||
type SelectStatement interface {
|
type SelectStatement interface {
|
||||||
Statement
|
Statement
|
||||||
jet.HasProjections
|
jet.HasProjections
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,13 @@ package postgres
|
||||||
|
|
||||||
import "github.com/go-jet/jet/internal/jet"
|
import "github.com/go-jet/jet/internal/jet"
|
||||||
|
|
||||||
|
// Table is interface for MySQL tables
|
||||||
|
type Table interface {
|
||||||
|
readableTable
|
||||||
|
writableTable
|
||||||
|
jet.SerializerTable
|
||||||
|
}
|
||||||
|
|
||||||
type readableTable interface {
|
type readableTable interface {
|
||||||
// Generates a select query on the current tableName.
|
// Generates a select query on the current tableName.
|
||||||
SELECT(projection Projection, projections ...Projection) SelectStatement
|
SELECT(projection Projection, projections ...Projection) SelectStatement
|
||||||
|
|
@ -35,18 +42,13 @@ type ReadableTable interface {
|
||||||
jet.Serializer
|
jet.Serializer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WritableTable interface
|
||||||
type WritableTable interface {
|
type WritableTable interface {
|
||||||
jet.Table
|
jet.Table
|
||||||
writableTable
|
writableTable
|
||||||
jet.Serializer
|
jet.Serializer
|
||||||
}
|
}
|
||||||
|
|
||||||
type Table interface {
|
|
||||||
readableTable
|
|
||||||
writableTable
|
|
||||||
jet.SerializerTable
|
|
||||||
}
|
|
||||||
|
|
||||||
type readableTableInterfaceImpl struct {
|
type readableTableInterfaceImpl struct {
|
||||||
parent ReadableTable
|
parent ReadableTable
|
||||||
}
|
}
|
||||||
|
|
@ -106,6 +108,7 @@ type table2Impl struct {
|
||||||
jet.TableImpl
|
jet.TableImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewTable creates new table with schema Name, table Name and list of columns
|
||||||
func NewTable(schemaName, name string, columns ...jet.ColumnExpression) Table {
|
func NewTable(schemaName, name string, columns ...jet.ColumnExpression) Table {
|
||||||
|
|
||||||
t := &table2Impl{
|
t := &table2Impl{
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,10 @@ package postgres
|
||||||
|
|
||||||
import "github.com/go-jet/jet/internal/jet"
|
import "github.com/go-jet/jet/internal/jet"
|
||||||
|
|
||||||
|
// Statement is common interface for all statements(SELECT, INSERT, UPDATE, DELETE, LOCK)
|
||||||
type Statement jet.Statement
|
type Statement jet.Statement
|
||||||
|
|
||||||
|
// Projection is interface for all projection types. Types that can be part of, for instance SELECT clause.
|
||||||
type Projection jet.Projection
|
type Projection jet.Projection
|
||||||
|
|
||||||
func toJetProjectionList(projections []Projection) []jet.Projection {
|
func toJetProjectionList(projections []Projection) []jet.Projection {
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,9 @@ type updateStatementImpl struct {
|
||||||
jet.StatementImpl
|
jet.StatementImpl
|
||||||
|
|
||||||
Update jet.ClauseUpdate
|
Update jet.ClauseUpdate
|
||||||
Set ClauseSet
|
Set clauseSet
|
||||||
Where jet.ClauseWhere
|
Where jet.ClauseWhere
|
||||||
Returning ClauseReturning
|
Returning clauseReturning
|
||||||
}
|
}
|
||||||
|
|
||||||
func newUpdateStatement(table WritableTable, columns []jet.Column) UpdateStatement {
|
func newUpdateStatement(table WritableTable, columns []jet.Column) UpdateStatement {
|
||||||
|
|
@ -56,12 +56,12 @@ func (u *updateStatementImpl) RETURNING(projections ...jet.Projection) UpdateSta
|
||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
||||||
type ClauseSet struct {
|
type clauseSet struct {
|
||||||
Columns []jet.Column
|
Columns []jet.Column
|
||||||
Values []jet.Serializer
|
Values []jet.Serializer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ClauseSet) Serialize(statementType jet.StatementType, out *jet.SqlBuilder) {
|
func (s *clauseSet) Serialize(statementType jet.StatementType, out *jet.SqlBuilder) {
|
||||||
out.NewLine()
|
out.NewLine()
|
||||||
out.WriteString("SET")
|
out.WriteString("SET")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue