Add support for postgres arrays
This commit is contained in:
parent
b835e25665
commit
d3ada5361e
27 changed files with 558 additions and 74 deletions
|
|
@ -45,6 +45,10 @@ type cast interface {
|
|||
AS_INTERVAL() IntervalExpression
|
||||
}
|
||||
|
||||
type castArray interface {
|
||||
AS_STRING() jet.ArrayExpression[StringExpression]
|
||||
}
|
||||
|
||||
type castImpl struct {
|
||||
jet.Cast
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,6 +101,24 @@ type ColumnInt8Range jet.ColumnRange[jet.Int8Expression]
|
|||
// Int8RangeColumn creates named range with range column
|
||||
var Int8RangeColumn = jet.RangeColumn[jet.Int8Expression]
|
||||
|
||||
// ColumnStringArray is interface of column
|
||||
type ColumnStringArray jet.ColumnArray[jet.StringExpression]
|
||||
|
||||
// StringArrayColumn creates named string array column
|
||||
var StringArrayColumn = jet.ArrayColumn[jet.StringExpression]
|
||||
|
||||
// ColumnIntegerArray is interface of column
|
||||
type ColumnIntegerArray jet.ColumnArray[jet.IntegerExpression]
|
||||
|
||||
// IntegerArrayColumn creates named integer array column
|
||||
var IntegerArrayColumn = jet.ArrayColumn[jet.IntegerExpression]
|
||||
|
||||
// ColumnBoolArray is interface of column
|
||||
type ColumnBoolArray jet.ColumnArray[jet.BoolExpression]
|
||||
|
||||
// BoolArrayColumn creates named bool array column
|
||||
var BoolArrayColumn = jet.ArrayColumn[jet.BoolExpression]
|
||||
|
||||
//------------------------------------------------------//
|
||||
|
||||
// ColumnInterval is interface of PostgreSQL interval columns.
|
||||
|
|
|
|||
|
|
@ -9,15 +9,24 @@ type Expression = jet.Expression
|
|||
// BoolExpression interface
|
||||
type BoolExpression = jet.BoolExpression
|
||||
|
||||
// BoolArrayExpression interface
|
||||
type BoolArrayExpression = jet.ArrayExpression[BoolExpression]
|
||||
|
||||
// StringExpression interface
|
||||
type StringExpression = jet.StringExpression
|
||||
|
||||
// StringArrayExpression interface
|
||||
type StringArrayExpression = jet.ArrayExpression[StringExpression]
|
||||
|
||||
// NumericExpression interface
|
||||
type NumericExpression = jet.NumericExpression
|
||||
|
||||
// IntegerExpression interface
|
||||
type IntegerExpression = jet.IntegerExpression
|
||||
|
||||
// IntegerArrayExpression interface
|
||||
type IntegerArrayExpression = jet.ArrayExpression[IntegerExpression]
|
||||
|
||||
// FloatExpression is interface
|
||||
type FloatExpression = jet.FloatExpression
|
||||
|
||||
|
|
|
|||
|
|
@ -175,27 +175,30 @@ RETURNING table1.col1 AS "table1.col1",
|
|||
}
|
||||
|
||||
func TestInsert_ON_CONFLICT_ON_CONSTRAINT(t *testing.T) {
|
||||
stmt := table1.INSERT(table1Col1, table1ColBool).
|
||||
VALUES("one", "two").
|
||||
VALUES("1", "2").
|
||||
stmt := table1.INSERT(table1Col1, table1ColBool, table1ColStringArray).
|
||||
VALUES("one", "two", "three").
|
||||
VALUES("1", "2", "3").
|
||||
ON_CONFLICT().ON_CONSTRAINT("idk_primary_key").DO_UPDATE(
|
||||
SET(table1ColBool.SET(Bool(false)),
|
||||
table2ColInt.SET(Int(1)),
|
||||
ColumnList{table1Col1, table1ColBool}.SET(jet.ROW(Int(2), String("two"))),
|
||||
table1ColStringArray.SET(StringArray([]string{"one"})),
|
||||
ColumnList{table1Col1, table1ColBool, table1ColStringArray}.SET(jet.ROW(Int(2), String("two"), StringArray([]string{"two"}))),
|
||||
).WHERE(table1Col1.GT(Int(2))),
|
||||
).
|
||||
RETURNING(table1Col1, table1ColBool)
|
||||
RETURNING(table1Col1, table1ColBool, table1ColStringArray)
|
||||
|
||||
assertDebugStatementSql(t, stmt, `
|
||||
INSERT INTO db.table1 (col1, col_bool)
|
||||
VALUES ('one', 'two'),
|
||||
('1', '2')
|
||||
INSERT INTO db.table1 (col1, col_bool, col_string_array)
|
||||
VALUES ('one', 'two', 'three'),
|
||||
('1', '2', '3')
|
||||
ON CONFLICT ON CONSTRAINT idk_primary_key DO UPDATE
|
||||
SET col_bool = FALSE::boolean,
|
||||
col_int = 1,
|
||||
(col1, col_bool) = ROW(2, 'two'::text)
|
||||
col_string_array = '{"one"}',
|
||||
(col1, col_bool, col_string_array) = ROW(2, 'two'::text, '{"two"}')
|
||||
WHERE table1.col1 > 2
|
||||
RETURNING table1.col1 AS "table1.col1",
|
||||
table1.col_bool AS "table1.col_bool";
|
||||
table1.col_bool AS "table1.col_bool",
|
||||
table1.col_string_array AS "table1.col_string_array";
|
||||
`)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@ func Bool(value bool) BoolExpression {
|
|||
return CAST(jet.Bool(value)).AS_BOOL()
|
||||
}
|
||||
|
||||
// BoolArray creates new bool array literal expression
|
||||
func BoolArray(elements []bool) BoolArrayExpression {
|
||||
return jet.BoolArray(elements)
|
||||
}
|
||||
|
||||
// Int is constructor for 64 bit signed integer expressions literals.
|
||||
var Int = jet.Int
|
||||
|
||||
|
|
@ -65,6 +70,11 @@ func String(value string) StringExpression {
|
|||
return CAST(jet.String(value)).AS_TEXT()
|
||||
}
|
||||
|
||||
// StringArray creates new string array literal expression
|
||||
func StringArray(elements []string) StringArrayExpression {
|
||||
return jet.StringArray(elements)
|
||||
}
|
||||
|
||||
// Json creates new json literal expression
|
||||
func Json(value interface{}) StringExpression {
|
||||
switch value.(type) {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ var table1ColBool = BoolColumn("col_bool")
|
|||
var table1ColDate = DateColumn("col_date")
|
||||
var table1ColInterval = IntervalColumn("col_interval")
|
||||
var table1ColRange = Int8RangeColumn("col_range")
|
||||
var table1ColStringArray = StringArrayColumn("col_string_array")
|
||||
var table1ColIntArray = IntegerArrayColumn("col_int_array")
|
||||
|
||||
var table1 = NewTable(
|
||||
"db",
|
||||
|
|
@ -34,6 +36,8 @@ var table1 = NewTable(
|
|||
table1ColTimestampz,
|
||||
table1ColInterval,
|
||||
table1ColRange,
|
||||
table1ColStringArray,
|
||||
table1ColIntArray,
|
||||
)
|
||||
|
||||
var table2Col3 = IntegerColumn("col3")
|
||||
|
|
@ -49,8 +53,10 @@ var table2ColTimestampz = TimestampzColumn("col_timestampz")
|
|||
var table2ColDate = DateColumn("col_date")
|
||||
var table2ColInterval = IntervalColumn("col_interval")
|
||||
var table2ColRange = Int8RangeColumn("col_range")
|
||||
var table2ColStringArray = StringArrayColumn("col_string_array")
|
||||
var table2ColIntArray = IntegerArrayColumn("col_int_array")
|
||||
|
||||
var table2 = NewTable("db", "table2", "", table2Col3, table2Col4, table2ColInt, table2ColFloat, table2ColStr, table2ColBool, table2ColTime, table2ColTimez, table2ColDate, table2ColTimestamp, table2ColTimestampz, table2ColInterval, table2ColRange)
|
||||
var table2 = NewTable("db", "table2", "", table2Col3, table2Col4, table2ColInt, table2ColFloat, table2ColStr, table2ColBool, table2ColTime, table2ColTimez, table2ColDate, table2ColTimestamp, table2ColTimestampz, table2ColInterval, table2ColRange, table2ColStringArray, table2ColIntArray)
|
||||
|
||||
var table3Col1 = IntegerColumn("col1")
|
||||
var table3ColInt = IntegerColumn("col_int")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue