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:
go-jet 2025-10-16 13:44:18 +02:00
commit 45d4ced9b0
25 changed files with 575 additions and 85 deletions

View file

@ -2,16 +2,15 @@ package template
import (
"fmt"
"github.com/go-jet/jet/v2/generator/metadata"
"github.com/go-jet/jet/v2/internal/utils/dbidentifier"
"github.com/google/uuid"
"github.com/jackc/pgtype"
"github.com/lib/pq"
"path/filepath"
"reflect"
"strings"
"time"
"github.com/google/uuid"
"github.com/jackc/pgtype"
"github.com/go-jet/jet/v2/generator/metadata"
"github.com/go-jet/jet/v2/internal/utils/dbidentifier"
)
// Model is template for model files generation
@ -260,7 +259,7 @@ func getUserDefinedType(column metadata.Column) string {
switch column.DataType.Kind {
case metadata.EnumType:
return dbidentifier.ToGoIdentifier(column.DataType.Name)
case metadata.UserDefinedType, metadata.ArrayType:
case metadata.UserDefinedType:
return "string"
}
@ -279,6 +278,11 @@ func getGoType(column metadata.Column) interface{} {
// toGoType returns model type for column info.
func toGoType(column metadata.Column) interface{} {
// We don't support multi-dimensional arrays
if column.DataType.Dimensions > 1 {
return ""
}
switch strings.ToLower(column.DataType.Name) {
case "user-defined", "enum":
return ""
@ -344,6 +348,14 @@ func toGoType(column metadata.Column) interface{} {
return pgtype.Int8range{}
case "numrange":
return pgtype.Numrange{}
case "bool[]":
return pq.BoolArray{}
case "integer[]", "int4[]":
return pq.Int32Array{}
case "bigint[]":
return pq.Int64Array{}
case "text[]", "jsonb[]", "json[]":
return pq.StringArray{}
default:
fmt.Println("- [Model ] Unsupported sql column '" + column.Name + " " + column.DataType.Name + "', using string instead.")
return ""