Skip to content

Commit 087f496

Browse files
authored
Added join processing for operation type one
1 parent 776bfe4 commit 087f496

File tree

1 file changed

+8
-28
lines changed

1 file changed

+8
-28
lines changed

gateway/modules/crud/sql/read.go

+8-28
Original file line numberDiff line numberDiff line change
@@ -279,34 +279,7 @@ func (s *SQL) readExec(ctx context.Context, col, sqlString string, args []interf
279279

280280
return 0, nil, nil, nil, errors.New("unknown error occurred")
281281

282-
case utils.One:
283-
mapping := make(map[string]interface{})
284-
if !rows.Next() {
285-
return 0, nil, nil, nil, errors.New("SQL: No response from db")
286-
}
287-
288-
err := rows.MapScan(mapping)
289-
if err != nil {
290-
return 0, nil, nil, nil, err
291-
}
292-
293-
switch s.GetDBType() {
294-
case model.MySQL, model.Postgres, model.SQLServer:
295-
mysqlTypeCheck(ctx, s.GetDBType(), rowTypes, mapping)
296-
}
297-
298-
processAggregate(mapping, mapping, col, isAggregate)
299-
if req.PostProcess != nil {
300-
_ = authHelpers.PostProcessMethod(ctx, s.aesKey, req.PostProcess[col], mapping)
301-
}
302-
303-
if req.Options.Debug {
304-
mapping["_dbFetchTs"] = time.Now().Format(time.RFC3339Nano)
305-
}
306-
307-
return 1, mapping, make(map[string]map[string]string), metaData, nil
308-
309-
case utils.All, utils.Distinct:
282+
case utils.All, utils.Distinct, utils.One:
310283
array := make([]interface{}, 0)
311284
mapping := make(map[string]map[string]interface{})
312285
jointMapping := make(map[string]map[string]string)
@@ -341,6 +314,13 @@ func (s *SQL) readExec(ctx context.Context, col, sqlString string, args []interf
341314
s.processRows(ctx, req.Options.Debug, []string{col}, isAggregate, row, req.Options.Join, mapping, &array, req.PostProcess, jointMapping)
342315
}
343316

317+
if operation == utils.One {
318+
if count == 0 {
319+
return 0, nil, nil, nil, errors.New("SQL: No response from db")
320+
}
321+
return 1, array[0], jointMapping, metaData, nil
322+
}
323+
344324
return count, array, jointMapping, metaData, nil
345325

346326
default:

0 commit comments

Comments
 (0)