Add support for CockorachDB.

This commit is contained in:
go-jet 2022-05-05 13:01:42 +02:00
parent 3ff9241eea
commit bc776f947b
33 changed files with 1040 additions and 1037 deletions

View file

@ -5,7 +5,7 @@ import (
)
func TestExpressionCAST_AS(t *testing.T) {
assertSerialize(t, CAST(String("test")).AS("text"), `$1::text`, "test")
assertSerialize(t, CAST(Int(11)).AS("text"), `$1::text`, int64(11))
}
func TestExpressionCAST_AS_BOOL(t *testing.T) {

View file

@ -4,16 +4,16 @@ import "testing"
func TestString_REGEXP_LIKE_operator(t *testing.T) {
assertSerialize(t, table3StrCol.REGEXP_LIKE(table2ColStr), "(table3.col2 ~* table2.col_str)")
assertSerialize(t, table3StrCol.REGEXP_LIKE(String("JOHN")), "(table3.col2 ~* $1)", "JOHN")
assertSerialize(t, table3StrCol.REGEXP_LIKE(String("JOHN"), false), "(table3.col2 ~* $1)", "JOHN")
assertSerialize(t, table3StrCol.REGEXP_LIKE(String("JOHN"), true), "(table3.col2 ~ $1)", "JOHN")
assertSerialize(t, table3StrCol.REGEXP_LIKE(String("JOHN")), "(table3.col2 ~* $1::text)", "JOHN")
assertSerialize(t, table3StrCol.REGEXP_LIKE(String("JOHN"), false), "(table3.col2 ~* $1::text)", "JOHN")
assertSerialize(t, table3StrCol.REGEXP_LIKE(String("JOHN"), true), "(table3.col2 ~ $1::text)", "JOHN")
}
func TestString_NOT_REGEXP_LIKE_operator(t *testing.T) {
assertSerialize(t, table3StrCol.NOT_REGEXP_LIKE(table2ColStr), "(table3.col2 !~* table2.col_str)")
assertSerialize(t, table3StrCol.NOT_REGEXP_LIKE(String("JOHN")), "(table3.col2 !~* $1)", "JOHN")
assertSerialize(t, table3StrCol.NOT_REGEXP_LIKE(String("JOHN"), false), "(table3.col2 !~* $1)", "JOHN")
assertSerialize(t, table3StrCol.NOT_REGEXP_LIKE(String("JOHN"), true), "(table3.col2 !~ $1)", "JOHN")
assertSerialize(t, table3StrCol.NOT_REGEXP_LIKE(String("JOHN")), "(table3.col2 !~* $1::text)", "JOHN")
assertSerialize(t, table3StrCol.NOT_REGEXP_LIKE(String("JOHN"), false), "(table3.col2 !~* $1::text)", "JOHN")
assertSerialize(t, table3StrCol.NOT_REGEXP_LIKE(String("JOHN"), true), "(table3.col2 !~ $1::text)", "JOHN")
}
func TestExists(t *testing.T) {

View file

@ -60,7 +60,7 @@ func TestRawHelperMethods(t *testing.T) {
assertSerialize(t, RawFloat("table.colInt + :float", RawArgs{":float": 11.22}).EQ(Float(3.14)),
"((table.colInt + $1) = $2)", 11.22, 3.14)
assertSerialize(t, RawString("table.colStr || str", RawArgs{"str": "doe"}).EQ(String("john doe")),
"((table.colStr || $1) = $2)", "doe", "john doe")
"((table.colStr || $1) = $2::text)", "doe", "john doe")
now := time.Now()
assertSerialize(t, RawTime("table.colTime").EQ(TimeT(now)),

View file

@ -167,7 +167,7 @@ VALUES ('one', 'two'),
ON CONFLICT (col_bool) WHERE col_bool IS NOT FALSE DO UPDATE
SET col_bool = TRUE::boolean,
col_int = 1,
(col1, col_bool) = ROW(2, 'two')
(col1, col_bool) = ROW(2, 'two'::text)
WHERE table1.col1 > 2
RETURNING table1.col1 AS "table1.col1",
table1.col_bool AS "table1.col_bool";
@ -193,7 +193,7 @@ VALUES ('one', 'two'),
ON CONFLICT ON CONSTRAINT idk_primary_key DO UPDATE
SET col_bool = FALSE::boolean,
col_int = 1,
(col1, col_bool) = ROW(2, 'two')
(col1, col_bool) = ROW(2, 'two'::text)
WHERE table1.col1 > 2
RETURNING table1.col1 AS "table1.col1",
table1.col_bool AS "table1.col_bool";

View file

@ -61,7 +61,9 @@ var Float = jet.Float
var Decimal = jet.Decimal
// String creates new string literal expression
var String = jet.String
func String(value string) StringExpression {
return CAST(jet.String(value)).AS_TEXT()
}
// UUID is a helper function to create string literal expression from uuid object
// value can be any uuid type with a String method

View file

@ -59,7 +59,7 @@ func TestFloat(t *testing.T) {
}
func TestString(t *testing.T) {
assertSerialize(t, String("Some text"), `$1`, "Some text")
assertSerialize(t, String("Some text"), `$1::text`, "Some text")
}
func TestBytea(t *testing.T) {