MCPcopy
hub / github.com/daptin/daptin / ResultToArrayOfMapWithTransaction

Method ResultToArrayOfMapWithTransaction

server/resource/dbmethods.go:3474–3923  ·  view source on GitHub ↗

ResultToArrayOfMap converts the result of db.QueryRowx => rows to array of data fetches the related objects also expects columnMap to be fetched from rows check usage in exiting source for example includeRelationMap can be nil to include none or map[string]bool{"*": true} to include all relations ca

(
	responseArray []map[string]interface{}, columnMap map[string]api2go.ColumnInfo,
	includedRelationMap map[string]bool, transaction *sqlx.Tx)

Source from the content-addressed store, hash-verified

3472// includeRelationMap can be nil to include none or map[string]bool{"*": true} to include all relations
3473// can be used on any *sqlx.Rows
3474func (dbResource *DbResource) ResultToArrayOfMapWithTransaction(
3475 responseArray []map[string]interface{}, columnMap map[string]api2go.ColumnInfo,
3476 includedRelationMap map[string]bool, transaction *sqlx.Tx) ([]map[string]interface{}, [][]map[string]interface{}, error) {
3477
3478 //finalArray := make([]map[string]interface{}, 0)
3479 if includedRelationMap == nil {
3480 includedRelationMap = make(map[string]bool)
3481 }
3482
3483 var err error
3484 objectCache := make(map[string]interface{})
3485 referenceIdCache := make(map[string]daptinid.DaptinReferenceId)
3486 includes := make([][]map[string]interface{}, 0)
3487
3488 for _, row := range responseArray {
3489 localInclude := make([]map[string]interface{}, 0)
3490
3491 for key, val := range row {
3492 //log.Printf("Key: [%v] == %v", key, val)
3493
3494 columnInfo, ok := columnMap[key]
3495 if !ok {
3496 continue
3497 }
3498
3499 if val != nil && columnInfo.ColumnType == "datetime" {
3500 stringVal, ok := val.(string)
3501 if ok {
3502 parsedValue, _, err := fieldtypes.GetTime(stringVal)
3503 if err != nil {
3504 parsedValue, _, err := fieldtypes.GetDateTime(stringVal)
3505 if InfoErr(err, "Failed to parse date time from [%v]: %v", columnInfo.ColumnName, stringVal) {
3506 row[key] = nil
3507 } else {
3508 row[key] = parsedValue
3509 }
3510 } else {
3511 row[key] = parsedValue
3512 }
3513 }
3514 }
3515
3516 if !columnInfo.IsForeignKey {
3517 continue
3518 }
3519
3520 if val == "" || val == nil {
3521 continue
3522 }
3523
3524 namespace := columnInfo.ForeignKeyData.Namespace
3525 //log.Printf("Resolve foreign key from [%v][%v][%v]", columnInfo.ForeignKeyData.DataSource, namespace, val)
3526 switch columnInfo.ForeignKeyData.DataSource {
3527 case "self":
3528
3529 referenceIdInt, ok := val.(int64)
3530 if !ok {
3531 stringIntId := val.(string)

Calls 15

TableInfoMethod · 0.95
makeFunction · 0.85
mailColumnBase64StringFunction · 0.85
isBuiltInMailBodyColumnFunction · 0.85
QueryxMethod · 0.80
ScanMethod · 0.80
ErrMethod · 0.80