fix: Correctly parse jsonb column tag (#2206)

Signed-off-by: Tamal Saha <tamal@appscode.com>
Co-authored-by: Tamal Saha <tamal@appscode.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2206
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: tamalsaha <tamalsaha@noreply.gitea.io>
Co-committed-by: tamalsaha <tamalsaha@noreply.gitea.io>
This commit is contained in:
tamalsaha 2023-01-09 13:19:29 +08:00 committed by Lunny Xiao
parent 71270edfcc
commit 5fafa00043
2 changed files with 24 additions and 1 deletions

View File

@ -557,6 +557,29 @@ func TestParseWithJSON(t *testing.T) {
assert.True(t, table.Columns()[0].IsJSON) assert.True(t, table.Columns()[0].IsJSON)
} }
func TestParseWithJSONB(t *testing.T) {
parser := NewParser(
"db",
dialects.QueryDialect("postgres"),
names.GonicMapper{
"JSONB": true,
},
names.SnakeMapper{},
caches.NewManager(),
)
type StructWithJSONB struct {
Default1 []string `db:"jsonb"`
}
table, err := parser.Parse(reflect.ValueOf(new(StructWithJSONB)))
assert.NoError(t, err)
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)
}
func TestParseWithSQLType(t *testing.T) { func TestParseWithSQLType(t *testing.T) {
parser := NewParser( parser := NewParser(
"db", "db",

View File

@ -285,7 +285,7 @@ func CommentTagHandler(ctx *Context) error {
// SQLTypeTagHandler describes SQL Type tag handler // SQLTypeTagHandler describes SQL Type tag handler
func SQLTypeTagHandler(ctx *Context) error { func SQLTypeTagHandler(ctx *Context) error {
ctx.col.SQLType = schemas.SQLType{Name: ctx.tagUname} ctx.col.SQLType = schemas.SQLType{Name: ctx.tagUname}
if ctx.tagUname == "JSON" { if ctx.tagUname == "JSON" || ctx.tagUname == "JSONB" {
ctx.col.IsJSON = true ctx.col.IsJSON = true
} }
if len(ctx.params) == 0 { if len(ctx.params) == 0 {