go-xorm / cmd

Command line tools for database operation written by Go, moved to https://gitea.com/xorm/cmd
BSD 3-Clause "New" or "Revised" License
168 stars 77 forks source link

postgresql数据库的josnb是空类型,映射string后有bug #22

Open sankeyou opened 7 years ago

sankeyou commented 7 years ago

postgresql数据库的josnb字段是允许为空 映射string后,插入数据时,字段不赋值,插入式给的是'' 不是nil 导致插入不进去,报错

模型 type Test struct { Id intxorm:"pk autoincr INT" Name stringxorm:"JSONB" }

访问数据库代码 test := model.Test{Id: 2} id, err := db.Insert(&test)

出错信息 [xorm] [info] 2017/07/27 14:28:04.194950 [SQL] INSERT INTO "test" ("id","name") VALUES ($1, $2) RETURNING "id" []interface {}{2, ""} pq: json类型使用了无效的输入语法

name是个jsonb 允许为空,会出错,插""是不行的,求更新!

lunny commented 7 years ago

Name interface{}?

sankeyou commented 7 years ago

@lunny 你觉的 name map[string]interface{} 怎么样,但是还是要解决那个空的问题 我测试如果映射成 map[string]interface{} 为空时 插入的是 'null'
这不合适吧?

lunny commented 7 years ago

null也是JSON支持的吧