[postgres] Add support for ON CONFLICT clause

This commit is contained in:
go-jet 2020-04-12 18:53:57 +02:00
parent eea776a1ac
commit 14e1863456
42 changed files with 827 additions and 277 deletions

View file

@ -13,15 +13,15 @@ func TestInvalidInsert(t *testing.T) {
func TestInsertNilValue(t *testing.T) {
assertStatementSql(t, table1.INSERT(table1Col1).VALUES(nil), `
INSERT INTO db.table1 (col1) VALUES
(?);
INSERT INTO db.table1 (col1)
VALUES (?);
`, nil)
}
func TestInsertSingleValue(t *testing.T) {
assertStatementSql(t, table1.INSERT(table1Col1).VALUES(1), `
INSERT INTO db.table1 (col1) VALUES
(?);
INSERT INTO db.table1 (col1)
VALUES (?);
`, int(1))
}
@ -31,8 +31,8 @@ func TestInsertWithColumnList(t *testing.T) {
columnList = append(columnList, table3StrCol)
assertStatementSql(t, table3.INSERT(columnList).VALUES(1, 3), `
INSERT INTO db.table3 (col_int, col2) VALUES
(?, ?);
INSERT INTO db.table3 (col_int, col2)
VALUES (?, ?);
`, 1, 3)
}
@ -40,15 +40,15 @@ func TestInsertDate(t *testing.T) {
date := time.Date(1999, 1, 2, 3, 4, 5, 0, time.UTC)
assertStatementSql(t, table1.INSERT(table1ColTimestamp).VALUES(date), `
INSERT INTO db.table1 (col_timestamp) VALUES
(?);
INSERT INTO db.table1 (col_timestamp)
VALUES (?);
`, date)
}
func TestInsertMultipleValues(t *testing.T) {
assertStatementSql(t, table1.INSERT(table1Col1, table1ColFloat, table1Col3).VALUES(1, 2, 3), `
INSERT INTO db.table1 (col1, col_float, col3) VALUES
(?, ?, ?);
INSERT INTO db.table1 (col1, col_float, col3)
VALUES (?, ?, ?);
`, 1, 2, 3)
}
@ -59,10 +59,10 @@ func TestInsertMultipleRows(t *testing.T) {
VALUES(111, 222)
assertStatementSql(t, stmt, `
INSERT INTO db.table1 (col1, col_float) VALUES
(?, ?),
(?, ?),
(?, ?);
INSERT INTO db.table1 (col1, col_float)
VALUES (?, ?),
(?, ?),
(?, ?);
`, 1, 2, 11, 22, 111, 222)
}
@ -84,9 +84,9 @@ func TestInsertValuesFromModel(t *testing.T) {
MODEL(&toInsert)
expectedSQL := `
INSERT INTO db.table1 (col1, col_float) VALUES
(?, ?),
(?, ?);
INSERT INTO db.table1 (col1, col_float)
VALUES (?, ?),
(?, ?);
`
assertStatementSql(t, stmt, expectedSQL, int(1), float64(1.11), int(1), float64(1.11))
@ -127,8 +127,8 @@ func TestInsertDefaultValue(t *testing.T) {
VALUES(DEFAULT, "two")
var expectedSQL = `
INSERT INTO db.table1 (col1, col_float) VALUES
(DEFAULT, ?);
INSERT INTO db.table1 (col1, col_float)
VALUES (DEFAULT, ?);
`
assertStatementSql(t, stmt, expectedSQL, "two")

View file

@ -77,9 +77,9 @@ func (r *readableTableInterfaceImpl) CROSS_JOIN(table ReadableTable) joinSelectU
}
// NewTable creates new table with schema Name, table Name and list of columns
func NewTable(schemaName, name string, column jet.ColumnExpression, columns ...jet.ColumnExpression) Table {
func NewTable(schemaName, name string, columns ...jet.ColumnExpression) Table {
t := &tableImpl{
SerializerTable: jet.NewTable(schemaName, name, column, columns...),
SerializerTable: jet.NewTable(schemaName, name, columns...),
}
t.readableTableInterfaceImpl.parent = t

View file

@ -5,9 +5,9 @@ import (
)
func TestJoinNilInputs(t *testing.T) {
assertClauseSerializeErr(t, table2.INNER_JOIN(nil, table1ColBool.EQ(table2ColBool)),
assertSerializeErr(t, table2.INNER_JOIN(nil, table1ColBool.EQ(table2ColBool)),
"jet: right hand side of join operation is nil table")
assertClauseSerializeErr(t, table2.INNER_JOIN(table1, nil),
assertSerializeErr(t, table2.INNER_JOIN(table1, nil),
"jet: join condition is nil")
}

View file

@ -59,15 +59,15 @@ var table3 = NewTable(
table3StrCol)
func assertSerialize(t *testing.T, clause jet.Serializer, query string, args ...interface{}) {
testutils.AssertClauseSerialize(t, Dialect, clause, query, args...)
testutils.AssertSerialize(t, Dialect, clause, query, args...)
}
func assertDebugSerialize(t *testing.T, clause jet.Serializer, query string, args ...interface{}) {
testutils.AssertDebugClauseSerialize(t, Dialect, clause, query, args...)
testutils.AssertDebugSerialize(t, Dialect, clause, query, args...)
}
func assertClauseSerializeErr(t *testing.T, clause jet.Serializer, errString string) {
testutils.AssertClauseSerializeErr(t, Dialect, clause, errString)
func assertSerializeErr(t *testing.T, clause jet.Serializer, errString string) {
testutils.AssertSerializeErr(t, Dialect, clause, errString)
}
func assertProjectionSerialize(t *testing.T, projection jet.Projection, query string, args ...interface{}) {