improvements

This commit is contained in:
Lunny Xiao 2025-07-17 15:54:16 -07:00
parent f17e4f5cd6
commit 6300ab092b
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
3 changed files with 5 additions and 4 deletions

View File

@ -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)

View File

@ -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) {

View File

@ -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
}