From 6300ab092b1e1d7c8925d9e2a08c3f45915103da Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 17 Jul 2025 15:54:16 -0700 Subject: [PATCH] improvements --- tags/parser.go | 6 +++--- tags/parser_test.go | 2 +- tags/tag.go | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tags/parser.go b/tags/parser.go index 358c8a21..8b97160e 100644 --- a/tags/parser.go +++ b/tags/parser.go @@ -250,10 +250,10 @@ func (parser *Parser) parseFieldWithTags(table *schemas.Table, fieldIndex int, f } if col.SQLType.Name == "" { - if col.IsJSON { - col.SQLType = schemas.SQLType{Name: schemas.Json} - } else if col.IsJSONB { + if col.IsJSONB { // check is jsonb first because it is also json col.SQLType = schemas.SQLType{Name: schemas.Jsonb} + } else if col.IsJSON { + col.SQLType = schemas.SQLType{Name: schemas.Json} } else { var err error col.SQLType, err = parser.getSQLTypeByType(field.Type) diff --git a/tags/parser_test.go b/tags/parser_test.go index 2c76d454..be6ea6fe 100644 --- a/tags/parser_test.go +++ b/tags/parser_test.go @@ -577,7 +577,7 @@ func TestParseWithJSONB(t *testing.T) { assert.EqualValues(t, "struct_with_jsonb", table.Name) assert.EqualValues(t, 1, len(table.Columns())) assert.EqualValues(t, "default1", table.Columns()[0].Name) - assert.True(t, table.Columns()[0].IsJSON) + assert.True(t, table.Columns()[0].IsJSONB) } func TestParseWithSQLType(t *testing.T) { diff --git a/tags/tag.go b/tags/tag.go index a11f2305..cfe35c8b 100644 --- a/tags/tag.go +++ b/tags/tag.go @@ -306,6 +306,7 @@ func JSONTagHandler(ctx *Context) error { func JSONBTagHandler(ctx *Context) error { ctx.col.IsJSONB = true + ctx.col.IsJSON = true // jsonb is also json return nil }