On this page:
query/ foldl
query/ map
query/ map/ filter
execute/ foldl
execute/ map
execute/ map/ filter

1.4 Query Catamorphisms

(query/foldl [#:connection con] proc init sql)  any/c
  con : connection? = (current-connection)
  proc : procedure?
  init : any/c
  sql : string?
Executes sql, left-folding proc over the resulting rows, using init as the initial seed. This call is semantically identical to:
  (let ((result (query #:connection con sql)))
    (if (result-set? result)
        (foldl (λ (x xs) (apply proc (append x (list xs))))
               init
               (map vector->list (result-set-rows result)))
        result))
... but is far more efficient in both time and space.

Note that the result of the query may be a side-effect, in which case no iteration occurs and the result is simply returned.

(query/map [#:connection con] proc sql?)
  (or/c side-effect? list?)
  con : connection? = (current-connection)
  proc : procedure?
  sql? : string?
Executes sql, mapping proc over the resulting rows. This call is semantically identical to:
  (let ((result (query #:connection con sql)))
    (if (result-set? result)
        (map (λ (xs) (apply proc xs))
             (map vector->list (result-set-rows result)))
        result))
... but is far more efficient in time and space.

(query/map/filter [#:connection con]    
  proc    
  pred?    
  sql)  (or/c side-effect? list?)
  con : connection? = (current-connection)
  proc : procedure?
  pred? : procedure?
  sql : string?
Executes sql, mapping proc over the rows in the result set that satisfy pred?. This call is semantically identical to:
  (let ((result (query #:connection con sql)))
    (if (result-set? result)
        (map (λ (xs) (apply proc xs))
             (filter (λ (xs) (apply pred? xs))
                     (map vector->list (result-set-rows result))))
        result))
... but is far more efficient in time and space.

(execute/foldl proc init stmt args)  any/c
  proc : procedure?
  init : any/c
  stmt : prepared-statement?
  args : list?
(execute/map proc stmt args)  (or/c side-effect list?)
  proc : procedure?
  stmt : prepared-statement?
  args : list?
(execute/map/filter proc pred? stmt args)
  (or/c side-effect? list?)
  proc : procedure?
  pred? : procedure?
  stmt : prepared-statement?
  args : list?
These procedures behave exactly like their query/... counterparts, except they take prepared statements and argument lists, rather than SQL strings.