orm: add json & jsonb type support

This commit is contained in:
miraclesu
2016-04-08 21:53:27 +08:00
parent 6da765c465
commit 657744efb1
5 changed files with 124 additions and 7 deletions

View File

@@ -90,6 +90,18 @@ checkColumn:
} else {
col = fmt.Sprintf(s, fi.digits, fi.decimals)
}
case TypeJsonField:
if al.Driver != DRPostgres {
fieldType = TypeCharField
goto checkColumn
}
col = T["json"]
case TypeJsonbField:
if al.Driver != DRPostgres {
fieldType = TypeCharField
goto checkColumn
}
col = T["jsonb"]
case RelForeignKey, RelOneToOne:
fieldType = fi.relModelInfo.fields.pk.fieldType
fieldSize = fi.relModelInfo.fields.pk.size
@@ -278,6 +290,8 @@ func getColumnDefault(fi *fieldInfo) string {
case TypeBooleanField:
t = " DEFAULT %s "
d = "FALSE"
case TypeJsonField, TypeJsonbField:
d = "{}"
}
if fi.colDefault {