feat(bun): generate native Go array slices for PostgreSQL array columns

Bun's pgdialect scans/appends native slices directly, so array columns
(text[], integer[], uuid[], ...) always generate as plain []string,
[]int32, etc. with an explicit "array" bun tag, regardless of --types
(sqltypes/stdlib/baselib). The SqlXxxArray wrapper types are no longer
used for Bun array columns (gorm is unaffected and keeps using them).

Adds --array-nullable pointer_slice to represent nullable array columns
as *[]T instead of []T, so callers can distinguish SQL NULL (nil) from
'{}' (pointer to an empty slice). Verified end-to-end against a live
PostgreSQL instance for NULL/{}/populated arrays in every --types mode.

Closes #13
This commit is contained in:
Hein
2026-07-21 12:41:38 +02:00
parent 2cecb4c11c
commit 5d9ff5df03
65 changed files with 9584 additions and 167 deletions
+26
View File
@@ -37,6 +37,23 @@ const (
NullableTypeBaselib = "baselib"
)
// NullableArrays constants control how nullable PostgreSQL array columns are
// represented in native-slice code-generation writers (Bun in stdlib/baselib
// mode).
const (
// NullableArraysSlice represents every array column (nullable or not) as
// a plain slice ([]string, []int32, …). SQL NULL and '{}' both scan into
// a zero-length/nil slice, so callers cannot distinguish them. This is
// the default.
NullableArraysSlice = "slice"
// NullableArraysPointerSlice represents nullable array columns as a
// pointer to a slice (*[]string, *[]int32, …), so callers can
// distinguish SQL NULL (nil pointer) from '{}' (pointer to an empty
// slice). NOT NULL array columns are unaffected and remain plain slices.
NullableArraysPointerSlice = "pointer_slice"
)
// WriterOptions contains common options for writers
type WriterOptions struct {
// OutputPath is the path where the output should be written
@@ -57,6 +74,15 @@ type WriterOptions struct {
// "baselib" (default) — plain Go pointer types (*string, *int32, …)
NullableTypes string
// NullableArrays selects how nullable PostgreSQL array columns are
// represented in native-slice code-generation writers (bun). Accepted values:
// "slice" (default) — plain slice for every array column
// "pointer_slice" — pointer-to-slice for nullable array columns,
// distinguishing SQL NULL from '{}'
// Has no effect in "sqltypes" NullableTypes mode, which always uses the
// SqlXxxArray wrapper types.
NullableArrays string
// Prisma7 enables Prisma 7-specific output for Prisma writers.
Prisma7 bool