Merge branch 'arjen-ag5/master' into pg_arrays
# Conflicts: # generator/template/model_template.go # generator/template/sql_builder_template.go # internal/jet/expression.go # postgres/cast.go # postgres/columns.go # postgres/expressions.go # postgres/insert_statement_test.go # postgres/literal.go # tests/postgres/alltypes_test.go # tests/postgres/generator_template_test.go # tests/postgres/scan_test.go # tests/postgres/select_test.go
This commit is contained in:
commit
45d4ced9b0
25 changed files with 575 additions and 85 deletions
|
|
@ -1,6 +1,8 @@
|
|||
package postgres
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"github.com/lib/pq"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"github.com/go-jet/jet/v2/internal/utils/ptr"
|
||||
|
|
@ -2243,12 +2245,12 @@ var allTypesRow0 = model.AllTypes{
|
|||
JSON: `{"a": 1, "b": 3}`,
|
||||
JsonbPtr: ptr.Of(`{"a": 1, "b": 3}`),
|
||||
Jsonb: `{"a": 1, "b": 3}`,
|
||||
IntegerArrayPtr: ptr.Of("{1,2,3}"),
|
||||
IntegerArray: "{1,2,3}",
|
||||
TextArrayPtr: ptr.Of("{breakfast,consulting}"),
|
||||
TextArray: "{breakfast,consulting}",
|
||||
JsonbArray: `{"{\"a\": 1, \"b\": 2}","{\"a\": 3, \"b\": 4}"}`,
|
||||
TextMultiDimArrayPtr: ptr.Of("{{meeting,lunch},{training,presentation}}"),
|
||||
IntegerArrayPtr: &pq.Int32Array{1, 2, 3},
|
||||
IntegerArray: pq.Int32Array{1, 2, 3},
|
||||
TextArrayPtr: &pq.StringArray{"breakfast", "consulting"},
|
||||
TextArray: pq.StringArray{"breakfast", "consulting"},
|
||||
JsonbArray: pq.StringArray{`{"a": 1, "b": 2}`, `{"a": 3, "b": 4}`},
|
||||
TextMultiDimArrayPtr: testutils.StringPtr("{{meeting,lunch},{training,presentation}}"),
|
||||
TextMultiDimArray: "{{meeting,lunch},{training,presentation}}",
|
||||
MoodPtr: &moodSad,
|
||||
Mood: model.Mood_Happy,
|
||||
|
|
@ -2312,10 +2314,10 @@ var allTypesRow1 = model.AllTypes{
|
|||
JsonbPtr: nil,
|
||||
Jsonb: `{"a": 1, "b": 3}`,
|
||||
IntegerArrayPtr: nil,
|
||||
IntegerArray: "{1,2,3}",
|
||||
IntegerArray: pq.Int32Array{1, 2, 3},
|
||||
TextArrayPtr: nil,
|
||||
TextArray: "{breakfast,consulting}",
|
||||
JsonbArray: `{"{\"a\": 1, \"b\": 2}","{\"a\": 3, \"b\": 4}"}`,
|
||||
TextArray: pq.StringArray{"breakfast", "consulting"},
|
||||
JsonbArray: pq.StringArray{`{"a": 1, "b": 2}`, `{"a": 3, "b": 4}`},
|
||||
TextMultiDimArrayPtr: nil,
|
||||
TextMultiDimArray: "{{meeting,lunch},{training,presentation}}",
|
||||
MoodPtr: nil,
|
||||
|
|
|
|||
|
|
@ -844,6 +844,7 @@ package model
|
|||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/lib/pq"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -902,11 +903,11 @@ type AllTypes struct {
|
|||
JSON string
|
||||
JsonbPtr *string
|
||||
Jsonb string
|
||||
IntegerArrayPtr *string
|
||||
IntegerArray string
|
||||
TextArrayPtr *string
|
||||
TextArray string
|
||||
JsonbArray string
|
||||
IntegerArrayPtr *pq.Int32Array
|
||||
IntegerArray pq.Int32Array
|
||||
TextArrayPtr *pq.StringArray
|
||||
TextArray pq.StringArray
|
||||
JsonbArray pq.StringArray
|
||||
TextMultiDimArrayPtr *string
|
||||
TextMultiDimArray string
|
||||
MoodPtr *Mood
|
||||
|
|
@ -1007,11 +1008,11 @@ type allTypesTable struct {
|
|||
JSON postgres.ColumnString
|
||||
JsonbPtr postgres.ColumnString
|
||||
Jsonb postgres.ColumnString
|
||||
IntegerArrayPtr postgres.ColumnString
|
||||
IntegerArray postgres.ColumnString
|
||||
TextArrayPtr postgres.ColumnString
|
||||
TextArray postgres.ColumnString
|
||||
JsonbArray postgres.ColumnString
|
||||
IntegerArrayPtr postgres.ColumnIntegerArray
|
||||
IntegerArray postgres.ColumnIntegerArray
|
||||
TextArrayPtr postgres.ColumnStringArray
|
||||
TextArray postgres.ColumnStringArray
|
||||
JsonbArray postgres.ColumnStringArray
|
||||
TextMultiDimArrayPtr postgres.ColumnString
|
||||
TextMultiDimArray postgres.ColumnString
|
||||
MoodPtr postgres.ColumnString
|
||||
|
|
@ -1111,11 +1112,11 @@ func newAllTypesTableImpl(schemaName, tableName, alias string) allTypesTable {
|
|||
JSONColumn = postgres.StringColumn("json")
|
||||
JsonbPtrColumn = postgres.StringColumn("jsonb_ptr")
|
||||
JsonbColumn = postgres.StringColumn("jsonb")
|
||||
IntegerArrayPtrColumn = postgres.StringColumn("integer_array_ptr")
|
||||
IntegerArrayColumn = postgres.StringColumn("integer_array")
|
||||
TextArrayPtrColumn = postgres.StringColumn("text_array_ptr")
|
||||
TextArrayColumn = postgres.StringColumn("text_array")
|
||||
JsonbArrayColumn = postgres.StringColumn("jsonb_array")
|
||||
IntegerArrayPtrColumn = postgres.IntegerArrayColumn("integer_array_ptr")
|
||||
IntegerArrayColumn = postgres.IntegerArrayColumn("integer_array")
|
||||
TextArrayPtrColumn = postgres.StringArrayColumn("text_array_ptr")
|
||||
TextArrayColumn = postgres.StringArrayColumn("text_array")
|
||||
JsonbArrayColumn = postgres.StringArrayColumn("jsonb_array")
|
||||
TextMultiDimArrayPtrColumn = postgres.StringColumn("text_multi_dim_array_ptr")
|
||||
TextMultiDimArrayColumn = postgres.StringColumn("text_multi_dim_array")
|
||||
MoodPtrColumn = postgres.StringColumn("mood_ptr")
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package postgres
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/lib/pq"
|
||||
"github.com/go-jet/jet/v2/internal/utils/ptr"
|
||||
"github.com/volatiletech/null/v8"
|
||||
"testing"
|
||||
|
|
@ -1006,6 +1007,7 @@ func TestScanIntoCustomBaseTypes(t *testing.T) {
|
|||
type MyFloat32 float32
|
||||
type MyFloat64 float64
|
||||
type MyString string
|
||||
type MyStringArray pq.StringArray
|
||||
type MyTime = time.Time
|
||||
|
||||
type film struct {
|
||||
|
|
@ -1020,26 +1022,25 @@ func TestScanIntoCustomBaseTypes(t *testing.T) {
|
|||
ReplacementCost MyFloat64
|
||||
Rating *model.MpaaRating
|
||||
LastUpdate MyTime
|
||||
SpecialFeatures *MyString
|
||||
SpecialFeatures MyStringArray
|
||||
Fulltext MyString
|
||||
}
|
||||
|
||||
// We'll skip special features, because it's a slice and it does not implement sql.Scanner
|
||||
stmt := SELECT(
|
||||
Film.AllColumns,
|
||||
Film.AllColumns.Except(Film.SpecialFeatures),
|
||||
).FROM(
|
||||
Film,
|
||||
).ORDER_BY(
|
||||
Film.FilmID.ASC(),
|
||||
).LIMIT(3)
|
||||
|
||||
var films []model.Film
|
||||
|
||||
err := stmt.Query(db, &films)
|
||||
var myFilms []film
|
||||
err := stmt.Query(db, &myFilms)
|
||||
require.NoError(t, err)
|
||||
|
||||
var myFilms []film
|
||||
|
||||
err = stmt.Query(db, &myFilms)
|
||||
var films []model.Film
|
||||
err = stmt.Query(db, &films)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, testutils.ToJSON(films), testutils.ToJSON(myFilms))
|
||||
|
|
@ -1254,7 +1255,7 @@ var film1 = model.Film{
|
|||
ReplacementCost: 20.99,
|
||||
Rating: &pgRating,
|
||||
LastUpdate: *testutils.TimestampWithoutTimeZone("2013-05-26 14:50:58.951", 3),
|
||||
SpecialFeatures: ptr.Of("{\"Deleted Scenes\",\"Behind the Scenes\"}"),
|
||||
SpecialFeatures: &pq.StringArray{"Deleted Scenes", "Behind the Scenes"},
|
||||
Fulltext: "'academi':1 'battl':15 'canadian':20 'dinosaur':2 'drama':5 'epic':4 'feminist':8 'mad':11 'must':14 'rocki':21 'scientist':12 'teacher':17",
|
||||
}
|
||||
|
||||
|
|
@ -1270,7 +1271,7 @@ var film2 = model.Film{
|
|||
ReplacementCost: 12.99,
|
||||
Rating: &gRating,
|
||||
LastUpdate: *testutils.TimestampWithoutTimeZone("2013-05-26 14:50:58.951", 3),
|
||||
SpecialFeatures: ptr.Of(`{Trailers,"Deleted Scenes"}`),
|
||||
SpecialFeatures: &pq.StringArray{"Trailers", "Deleted Scenes"},
|
||||
Fulltext: `'ace':1 'administr':9 'ancient':19 'astound':4 'car':17 'china':20 'databas':8 'epistl':5 'explor':12 'find':15 'goldfing':2 'must':14`,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
"github.com/go-jet/jet/v2/internal/utils/ptr"
|
||||
"github.com/lib/pq"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -1852,7 +1853,7 @@ ORDER BY film.film_id ASC;
|
|||
Rating: &gRating,
|
||||
RentalDuration: 3,
|
||||
LastUpdate: *testutils.TimestampWithoutTimeZone("2013-05-26 14:50:58.951", 3),
|
||||
SpecialFeatures: ptr.Of("{Trailers,\"Deleted Scenes\"}"),
|
||||
SpecialFeatures: &pq.StringArray{"Trailers", "Deleted Scenes"},
|
||||
Fulltext: "'ace':1 'administr':9 'ancient':19 'astound':4 'car':17 'china':20 'databas':8 'epistl':5 'explor':12 'find':15 'goldfing':2 'must':14",
|
||||
})
|
||||
}
|
||||
|
|
@ -2783,7 +2784,6 @@ ORDER BY actor.actor_id ASC, film.film_id ASC;
|
|||
require.NoError(t, err)
|
||||
|
||||
//testutils.SaveJSONFile(dest, "./testdata/results/postgres/quick-start-dest.json")
|
||||
|
||||
testutils.AssertJSONFile(t, dest, "./testdata/results/postgres/quick-start-dest.json")
|
||||
|
||||
var dest2 []struct {
|
||||
|
|
@ -2798,7 +2798,7 @@ ORDER BY actor.actor_id ASC, film.film_id ASC;
|
|||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
//testutils.SaveJSONFile(dest2, "./testdata/results/postgres/quick-start-dest2.json")
|
||||
//testutils.SaveJSONFile(dest, "./testdata/results/postgres/quick-start-dest2.json")
|
||||
testutils.AssertJSONFile(t, dest2, "./testdata/results/postgres/quick-start-dest2.json")
|
||||
}
|
||||
|
||||
|
|
@ -3389,7 +3389,10 @@ func TestSelectRecursionScanNxM(t *testing.T) {
|
|||
"ReplacementCost": 20.99,
|
||||
"Rating": "PG",
|
||||
"LastUpdate": "2013-05-26T14:50:58.951Z",
|
||||
"SpecialFeatures": "{\"Deleted Scenes\",\"Behind the Scenes\"}",
|
||||
"SpecialFeatures": [
|
||||
"Deleted Scenes",
|
||||
"Behind the Scenes"
|
||||
],
|
||||
"Fulltext": "'academi':1 'battl':15 'canadian':20 'dinosaur':2 'drama':5 'epic':4 'feminist':8 'mad':11 'must':14 'rocki':21 'scientist':12 'teacher':17",
|
||||
"Actors": [
|
||||
{
|
||||
|
|
@ -3413,7 +3416,10 @@ func TestSelectRecursionScanNxM(t *testing.T) {
|
|||
"ReplacementCost": 9.99,
|
||||
"Rating": "R",
|
||||
"LastUpdate": "2013-05-26T14:50:58.951Z",
|
||||
"SpecialFeatures": "{Trailers,\"Deleted Scenes\"}",
|
||||
"SpecialFeatures": [
|
||||
"Trailers",
|
||||
"Deleted Scenes"
|
||||
],
|
||||
"Fulltext": "'anaconda':1 'australia':18 'confess':2 'dentist':8,11 'display':5 'fight':14 'girl':16 'lacklustur':4 'must':13",
|
||||
"Actors": [
|
||||
{
|
||||
|
|
@ -3461,7 +3467,10 @@ func TestSelectRecursionScanNxM(t *testing.T) {
|
|||
"ReplacementCost": 20.99,
|
||||
"Rating": "PG",
|
||||
"LastUpdate": "2013-05-26T14:50:58.951Z",
|
||||
"SpecialFeatures": "{\"Deleted Scenes\",\"Behind the Scenes\"}",
|
||||
"SpecialFeatures": [
|
||||
"Deleted Scenes",
|
||||
"Behind the Scenes"
|
||||
],
|
||||
"Fulltext": "'academi':1 'battl':15 'canadian':20 'dinosaur':2 'drama':5 'epic':4 'feminist':8 'mad':11 'must':14 'rocki':21 'scientist':12 'teacher':17",
|
||||
"Actors": null
|
||||
},
|
||||
|
|
@ -3477,7 +3486,10 @@ func TestSelectRecursionScanNxM(t *testing.T) {
|
|||
"ReplacementCost": 9.99,
|
||||
"Rating": "R",
|
||||
"LastUpdate": "2013-05-26T14:50:58.951Z",
|
||||
"SpecialFeatures": "{Trailers,\"Deleted Scenes\"}",
|
||||
"SpecialFeatures": [
|
||||
"Trailers",
|
||||
"Deleted Scenes"
|
||||
],
|
||||
"Fulltext": "'anaconda':1 'australia':18 'confess':2 'dentist':8,11 'display':5 'fight':14 'girl':16 'lacklustur':4 'must':13",
|
||||
"Actors": null
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue