MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / FromDBMap

Function FromDBMap

pkg/util/dbutil/dbmappable.go:191–237  ·  view source on GitHub ↗
(v DBMappable, m map[string]interface{})

Source from the content-addressed store, hash-verified

189}
190
191func FromDBMap(v DBMappable, m map[string]interface{}) {
192 if CheckNil(v) {
193 panic("StructFromDBMap, v cannot be nil")
194 }
195 rv := reflect.ValueOf(v)
196 if rv.Kind() == reflect.Pointer {
197 rv = rv.Elem()
198 }
199 if rv.Kind() != reflect.Struct {
200 panic(fmt.Sprintf("invalid type %T (non-struct) passed to StructFromDBMap", v))
201 }
202 rt := rv.Type()
203 numFields := rt.NumField()
204 for i := 0; i < numFields; i++ {
205 field := rt.Field(i)
206 fieldVal := rv.FieldByIndex(field.Index)
207 dbName := field.Tag.Get("dbmap")
208 if dbName == "" {
209 dbName = strings.ToLower(field.Name)
210 }
211 if dbName == "-" {
212 continue
213 }
214 if isByteArrayType(field.Type) {
215 barrVal := fieldVal.Addr().Interface()
216 QuickSetBytes(barrVal.(*[]byte), m, dbName)
217 } else if field.Type.Kind() == reflect.Slice {
218 QuickSetJsonArr(fieldVal.Addr().Interface(), m, dbName)
219 } else if isStructType(field.Type) || isStringMapType(field.Type) {
220 QuickSetJson(fieldVal.Addr().Interface(), m, dbName)
221 } else if field.Type.Kind() == reflect.String {
222 strVal := fieldVal.Addr().Interface()
223 QuickSetStr(strVal.(*string), m, dbName)
224 } else if field.Type.Kind() == reflect.Int64 {
225 intVal := fieldVal.Addr().Interface()
226 QuickSetInt64(intVal.(*int64), m, dbName)
227 } else if field.Type.Kind() == reflect.Int {
228 intVal := fieldVal.Addr().Interface()
229 QuickSetInt(intVal.(*int), m, dbName)
230 } else if field.Type.Kind() == reflect.Bool {
231 boolVal := fieldVal.Addr().Interface()
232 QuickSetBool(boolVal.(*bool), m, dbName)
233 } else {
234 panic(fmt.Sprintf("StructFromDBMap invalid field type %v in %T", fieldVal.Type(), v))
235 }
236 }
237}

Callers 2

GetMappableFunction · 0.85
SelectMappableFunction · 0.85

Calls 13

CheckNilFunction · 0.85
isByteArrayTypeFunction · 0.85
QuickSetBytesFunction · 0.85
QuickSetJsonArrFunction · 0.85
isStructTypeFunction · 0.85
isStringMapTypeFunction · 0.85
QuickSetJsonFunction · 0.85
QuickSetStrFunction · 0.85
QuickSetInt64Function · 0.85
QuickSetIntFunction · 0.85
QuickSetBoolFunction · 0.85
TypeMethod · 0.80

Tested by

no test coverage detected