MCPcopy Create free account
hub / github.com/cloudwan/gohan / decode

Method decode

db/sql/sql.go:1050–1076  ·  view source on GitHub ↗
(s *schema.Schema, tableName string, skipNil, recursive bool, data map[string]interface{})

Source from the content-addressed store, hash-verified

1048}
1049
1050func (tx *Transaction) decode(s *schema.Schema, tableName string, skipNil, recursive bool, data map[string]interface{}) map[string]interface{} {
1051 resourceData := map[string]interface{}{}
1052
1053 manager := schema.GetManager()
1054 db := tx.db
1055 for _, property := range s.Properties {
1056 handler := db.handler(&property)
1057 value := data[makeColumnID(tableName, property)]
1058 if value != nil || (property.Nullable && !skipNil) {
1059 decoded, err := handler.decode(&property, value)
1060 if err != nil {
1061 log.Error(fmt.Sprintf("SQL List decoding error: %s", err))
1062 }
1063 resourceData[property.ID] = decoded
1064 }
1065 if property.RelationProperty != "" && recursive {
1066 relatedSchema, _ := manager.Schema(property.Relation)
1067 aliasTableName := makeAliasTableName(tableName, property)
1068 relatedResourceData := tx.decode(relatedSchema, aliasTableName, skipNil, recursive, data)
1069 if len(relatedResourceData) > 0 || !skipNil {
1070 resourceData[property.RelationProperty] = relatedResourceData
1071 }
1072 }
1073 }
1074
1075 return resourceData
1076}
1077
1078//CountContext count all matching resources in the db
1079func (tx *Transaction) CountContext(ctx context.Context, s *schema.Schema, filter transaction.Filter) (res uint64, err error) {

Callers 1

decodeRowsMethod · 0.95

Calls 6

makeColumnIDFunction · 0.85
makeAliasTableNameFunction · 0.85
handlerMethod · 0.80
decodeMethod · 0.65
ErrorMethod · 0.65
SchemaMethod · 0.65

Tested by

no test coverage detected