@@ -53,13 +53,14 @@ func Init(modelType reflect.Type, db *sql.DB) (map[string]int, *Schema, map[stri
53
53
schema := CreateSchema (modelType )
54
54
fields := BuildFieldsBySchema (schema )
55
55
jsonColumnMap := MakeJsonColumnMap (modelType )
56
+ jm := GetWritableColumns (schema .Fields , jsonColumnMap )
56
57
keys , arr := FindPrimaryKeys (modelType )
57
58
if db == nil {
58
- return fieldsIndex , schema , jsonColumnMap , keys , arr , fields , nil , "" , nil
59
+ return fieldsIndex , schema , jm , keys , arr , fields , nil , "" , nil
59
60
}
60
61
driver := GetDriver (db )
61
62
buildParam := GetBuild (db )
62
- return fieldsIndex , schema , jsonColumnMap , keys , arr , fields , buildParam , driver , nil
63
+ return fieldsIndex , schema , jm , keys , arr , fields , buildParam , driver , nil
63
64
}
64
65
type Writer struct {
65
66
* Loader
@@ -113,7 +114,8 @@ func NewSqlWriterWithVersion(db *sql.DB, tableName string, modelType reflect.Typ
113
114
driver := GetDriver (db )
114
115
boolSupport := driver == DriverPostgres
115
116
schema := CreateSchema (modelType )
116
- jsonColumnMap := MakeJsonColumnMap (modelType )
117
+ jsonColumnMapT := MakeJsonColumnMap (modelType )
118
+ jsonColumnMap := GetWritableColumns (schema .Fields , jsonColumnMapT )
117
119
if len (versionField ) > 0 {
118
120
index := FindFieldIndex (modelType , versionField )
119
121
if index >= 0 {
@@ -439,6 +441,20 @@ func JSONToColumns(model map[string]interface{}, m map[string]string) map[string
439
441
}
440
442
return r
441
443
}
444
+ func GetWritableColumns (fields map [string ]* FieldDB , jsonColumnMap map [string ]string ) map [string ]string {
445
+ m := jsonColumnMap
446
+ for k , v := range jsonColumnMap {
447
+ for _ , db := range fields {
448
+ if db .Column == v {
449
+ if db .Update == false && db .Key == false {
450
+ delete (m , k )
451
+ }
452
+ }
453
+ }
454
+ }
455
+ return m
456
+ }
457
+
442
458
func Contains (s []string , str string ) bool {
443
459
for _ , v := range s {
444
460
if v == str {
0 commit comments