feat: add --types flag and stdlib nullable type support for bun/gorm writers
* Fix pgsql reader double-quoting defaults: normalizePostgresDefault strips surrounding SQL string literal quotes from column_default before storing, matching the convention used by every other reader. * Add NullableTypes field to WriterOptions with NullableTypeResolveSpec (default) and NullableTypeStdlib constants. * Both bun and gorm TypeMappers now accept a typeStyle parameter. stdlib mode produces sql.NullString/NullInt32/NullTime etc. for nullable scalars, plain Go slices for arrays, and time.Time for NOT NULL timestamps. Default resolvespec behaviour is unchanged. * Add --types flag to convert and split commands. * Update bun/README.md and gorm/README.md with side-by-side generated code examples, updated type mapping tables, and Writer Options documentation.
This commit is contained in:
@@ -20,6 +20,18 @@ type Writer interface {
|
||||
WriteTable(table *models.Table) error
|
||||
}
|
||||
|
||||
// NullableType constants control which Go package is used for nullable column types
|
||||
// in code-generation writers (Bun, GORM).
|
||||
const (
|
||||
// NullableTypeResolveSpec uses github.com/bitechdev/ResolveSpec/pkg/spectypes
|
||||
// (SqlString, SqlInt32, SqlVector, SqlStringArray, …). This is the default.
|
||||
NullableTypeResolveSpec = "resolvespec"
|
||||
|
||||
// NullableTypeStdlib uses the standard library database/sql nullable types
|
||||
// (sql.NullString, sql.NullInt32, …) and plain Go slices for arrays.
|
||||
NullableTypeStdlib = "stdlib"
|
||||
)
|
||||
|
||||
// WriterOptions contains common options for writers
|
||||
type WriterOptions struct {
|
||||
// OutputPath is the path where the output should be written
|
||||
@@ -33,6 +45,12 @@ type WriterOptions struct {
|
||||
// Useful for databases like SQLite that do not support schemas.
|
||||
FlattenSchema bool
|
||||
|
||||
// NullableTypes selects the Go type package used for nullable columns in
|
||||
// code-generation writers (bun, gorm). Accepted values:
|
||||
// "resolvespec" (default) — github.com/bitechdev/ResolveSpec/pkg/spectypes
|
||||
// "stdlib" — database/sql (sql.NullString, sql.NullInt32, …)
|
||||
NullableTypes string
|
||||
|
||||
// Additional options can be added here as needed
|
||||
Metadata map[string]interface{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user