mirror of
https://github.com/astaxie/beego.git
synced 2024-11-29 17:11:29 +00:00
orm: add test case for json & jsonb type support
This commit is contained in:
parent
657744efb1
commit
e95bef1331
@ -112,6 +112,8 @@ type Data struct {
|
|||||||
Boolean bool
|
Boolean bool
|
||||||
Char string `orm:"size(50)"`
|
Char string `orm:"size(50)"`
|
||||||
Text string `orm:"type(text)"`
|
Text string `orm:"type(text)"`
|
||||||
|
Json string `orm:"type(json);default({\"name\":\"json\"})"`
|
||||||
|
Jsonb string `orm:"type(jsonb)"`
|
||||||
Time time.Time `orm:"type(time)"`
|
Time time.Time `orm:"type(time)"`
|
||||||
Date time.Time `orm:"type(date)"`
|
Date time.Time `orm:"type(date)"`
|
||||||
DateTime time.Time `orm:"column(datetime)"`
|
DateTime time.Time `orm:"column(datetime)"`
|
||||||
@ -137,6 +139,8 @@ type DataNull struct {
|
|||||||
Boolean bool `orm:"null"`
|
Boolean bool `orm:"null"`
|
||||||
Char string `orm:"null;size(50)"`
|
Char string `orm:"null;size(50)"`
|
||||||
Text string `orm:"null;type(text)"`
|
Text string `orm:"null;type(text)"`
|
||||||
|
Json string `orm:"type(json);null"`
|
||||||
|
Jsonb string `orm:"type(jsonb);null"`
|
||||||
Time time.Time `orm:"null;type(time)"`
|
Time time.Time `orm:"null;type(time)"`
|
||||||
Date time.Time `orm:"null;type(date)"`
|
Date time.Time `orm:"null;type(date)"`
|
||||||
DateTime time.Time `orm:"null;column(datetime)"`
|
DateTime time.Time `orm:"null;column(datetime)"`
|
||||||
|
@ -241,6 +241,8 @@ var DataValues = map[string]interface{}{
|
|||||||
"Boolean": true,
|
"Boolean": true,
|
||||||
"Char": "char",
|
"Char": "char",
|
||||||
"Text": "text",
|
"Text": "text",
|
||||||
|
"Json": `{"name":"json"}`,
|
||||||
|
"Jsonb": `{"name": "jsonb"}`,
|
||||||
"Time": time.Now(),
|
"Time": time.Now(),
|
||||||
"Date": time.Now(),
|
"Date": time.Now(),
|
||||||
"DateTime": time.Now(),
|
"DateTime": time.Now(),
|
||||||
@ -266,6 +268,9 @@ func TestDataTypes(t *testing.T) {
|
|||||||
ind := reflect.Indirect(reflect.ValueOf(&d))
|
ind := reflect.Indirect(reflect.ValueOf(&d))
|
||||||
|
|
||||||
for name, value := range DataValues {
|
for name, value := range DataValues {
|
||||||
|
if name == "Json" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
e := ind.FieldByName(name)
|
e := ind.FieldByName(name)
|
||||||
e.Set(reflect.ValueOf(value))
|
e.Set(reflect.ValueOf(value))
|
||||||
}
|
}
|
||||||
@ -310,10 +315,18 @@ func TestNullDataTypes(t *testing.T) {
|
|||||||
throwFail(t, err)
|
throwFail(t, err)
|
||||||
throwFail(t, AssertIs(id, 1))
|
throwFail(t, AssertIs(id, 1))
|
||||||
|
|
||||||
|
data := `{"ok":1,"data":{"arr":[1,2],"msg":"gopher"}}`
|
||||||
|
d = DataNull{ID: 1, Json: data}
|
||||||
|
num, err := dORM.Update(&d)
|
||||||
|
throwFail(t, err)
|
||||||
|
throwFail(t, AssertIs(num, 1))
|
||||||
|
|
||||||
d = DataNull{ID: 1}
|
d = DataNull{ID: 1}
|
||||||
err = dORM.Read(&d)
|
err = dORM.Read(&d)
|
||||||
throwFail(t, err)
|
throwFail(t, err)
|
||||||
|
|
||||||
|
throwFail(t, AssertIs(d.Json, data))
|
||||||
|
|
||||||
throwFail(t, AssertIs(d.NullBool.Valid, false))
|
throwFail(t, AssertIs(d.NullBool.Valid, false))
|
||||||
throwFail(t, AssertIs(d.NullString.Valid, false))
|
throwFail(t, AssertIs(d.NullString.Valid, false))
|
||||||
throwFail(t, AssertIs(d.NullInt64.Valid, false))
|
throwFail(t, AssertIs(d.NullInt64.Valid, false))
|
||||||
|
Loading…
Reference in New Issue
Block a user