@@ -291,38 +291,43 @@ func (c *Client) processQueryResults(query string, results []surrealdb.QueryResu
291291 continue
292292 }
293293
294- if resultList , ok := result .Result .([]any ); ok {
295- for _ , record := range resultList {
296- extracted , err := c .extractRecord (record )
297- if err != nil {
298- c .logger .Errorf ("failed to extract record: %v" , err )
299- continue
300- }
301-
302- resp = append (resp , extracted )
303- }
304- } else if resultMap , ok := result .Result .(map [string ]any ); ok {
305- // Handle single record returned as map directly (e.g., from type::thing() queries)
306- extracted , err := c .extractRecord (resultMap )
307- if err != nil {
308- c .logger .Errorf ("failed to extract record: %v" , err )
309- } else {
310- resp = append (resp , extracted )
311- }
312- } else if resultMap , ok := result .Result .(map [any ]any ); ok {
313- // Handle single record as map[any]any for compatibility
314- extracted , err := c .extractRecord (resultMap )
294+ c .handleResultRecord (result .Result , & resp )
295+ }
296+
297+ return resp , nil
298+ }
299+
300+ // handleResultRecord processes a single result record and appends to response.
301+ func (c * Client ) handleResultRecord (result any , resp * []any ) {
302+ switch res := result .(type ) {
303+ case []any :
304+ for _ , record := range res {
305+ extracted , err := c .extractRecord (record )
315306 if err != nil {
316307 c .logger .Errorf ("failed to extract record: %v" , err )
317- } else {
318- resp = append (resp , extracted )
308+ continue
319309 }
310+ * resp = append (* resp , extracted )
311+ }
312+ case map [string ]any :
313+ // Handle single record returned as map directly (e.g., from type::thing() queries)
314+ extracted , err := c .extractRecord (res )
315+ if err != nil {
316+ c .logger .Errorf ("failed to extract record: %v" , err )
317+ } else {
318+ * resp = append (* resp , extracted )
319+ }
320+ case map [any ]any :
321+ // Handle single record as map[any]any for compatibility
322+ extracted , err := c .extractRecord (res )
323+ if err != nil {
324+ c .logger .Errorf ("failed to extract record: %v" , err )
320325 } else {
321- resp = append (resp , result . Result )
326+ * resp = append (* resp , extracted )
322327 }
328+ default :
329+ * resp = append (* resp , result )
323330 }
324-
325- return resp , nil
326331}
327332
328333// extractRecord extracts and processes a single record into a map[string]any}.
0 commit comments