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:
@@ -24,7 +24,7 @@ type Writer struct {
|
||||
func NewWriter(options *writers.WriterOptions) *Writer {
|
||||
w := &Writer{
|
||||
options: options,
|
||||
typeMapper: NewTypeMapper(),
|
||||
typeMapper: NewTypeMapper(options.NullableTypes),
|
||||
config: LoadMethodConfigFromMetadata(options.Metadata),
|
||||
}
|
||||
|
||||
@@ -80,8 +80,8 @@ func (w *Writer) writeSingleFile(db *models.Database) error {
|
||||
// Add bun import (always needed)
|
||||
templateData.AddImport(fmt.Sprintf("\"%s\"", w.typeMapper.GetBunImport()))
|
||||
|
||||
// Add resolvespec_common import (always needed for nullable types)
|
||||
templateData.AddImport(fmt.Sprintf("resolvespec_common \"%s\"", w.typeMapper.GetSQLTypesImport()))
|
||||
// Add nullable types import (resolvespec or stdlib depending on options)
|
||||
templateData.AddImport(w.typeMapper.GetNullableTypeImportLine())
|
||||
|
||||
// Collect all models
|
||||
for _, schema := range db.Schemas {
|
||||
@@ -177,8 +177,8 @@ func (w *Writer) writeMultiFile(db *models.Database) error {
|
||||
// Add bun import
|
||||
templateData.AddImport(fmt.Sprintf("\"%s\"", w.typeMapper.GetBunImport()))
|
||||
|
||||
// Add resolvespec_common import
|
||||
templateData.AddImport(fmt.Sprintf("resolvespec_common \"%s\"", w.typeMapper.GetSQLTypesImport()))
|
||||
// Add nullable types import (resolvespec or stdlib depending on options)
|
||||
templateData.AddImport(w.typeMapper.GetNullableTypeImportLine())
|
||||
|
||||
// Create model data
|
||||
modelData := NewModelData(table, schema.Name, w.typeMapper, w.options.FlattenSchema)
|
||||
|
||||
Reference in New Issue
Block a user