@@ -119,10 +119,17 @@ type ConvConfig struct {
119
119
}
120
120
121
121
func (s * ConvConfig ) FromDB (data []byte ) error {
122
+ if data == nil {
123
+ s = nil
124
+ return nil
125
+ }
122
126
return json .DefaultJSONHandler .Unmarshal (data , s )
123
127
}
124
128
125
129
func (s * ConvConfig ) ToDB () ([]byte , error ) {
130
+ if s == nil {
131
+ return nil , nil
132
+ }
126
133
return json .DefaultJSONHandler .Marshal (s )
127
134
}
128
135
@@ -184,6 +191,30 @@ func TestConversion(t *testing.T) {
184
191
assert .EqualValues (t , 2 , len (c1 .Slice ))
185
192
assert .EqualValues (t , * c .Slice [0 ], * c1 .Slice [0 ])
186
193
assert .EqualValues (t , * c .Slice [1 ], * c1 .Slice [1 ])
194
+
195
+ cnt , err := testEngine .Where ("1=1" ).Delete (new (ConvStruct ))
196
+ assert .NoError (t , err )
197
+ assert .EqualValues (t , 1 , cnt )
198
+
199
+ c .Cfg2 = nil
200
+
201
+ _ , err = testEngine .Insert (c )
202
+ assert .NoError (t , err )
203
+
204
+ c2 := new (ConvStruct )
205
+ has , err = testEngine .Get (c2 )
206
+ assert .NoError (t , err )
207
+ assert .True (t , has )
208
+ assert .EqualValues (t , "prefix---tttt" , string (c2 .Conv ))
209
+ assert .NotNil (t , c2 .Conv2 )
210
+ assert .EqualValues (t , "prefix---" + s , * c2 .Conv2 )
211
+ assert .EqualValues (t , c .Cfg1 , c2 .Cfg1 )
212
+ assert .Nil (t , c2 .Cfg2 )
213
+ assert .NotNil (t , c2 .Cfg3 )
214
+ assert .EqualValues (t , * c .Cfg3 .(* ConvConfig ), * c2 .Cfg3 .(* ConvConfig ))
215
+ assert .EqualValues (t , 2 , len (c2 .Slice ))
216
+ assert .EqualValues (t , * c .Slice [0 ], * c2 .Slice [0 ])
217
+ assert .EqualValues (t , * c .Slice [1 ], * c2 .Slice [1 ])
187
218
}
188
219
189
220
type MyInt int
0 commit comments