On this page:
with-mock-data
db-funcs-init

2 dtb🔗ℹ

syntax

(with-mock-data (~or mock-data-definition #:datadef) body ...)

Defines a block where all database data will be mocked. First value to be provided is a list of lists defining the mock data. First value of this list is the identifier that will be mocked, such as a datadef or a query function generated via the dtb module. The second value for datadef entries is expected to be the position of mock data in the datadef definition, for dtb functions it is expected to be a list of mock data. The dtb functions can optionally receive a third value, which can be a list of indices that will be used to retrieve data from the mock data defined in the second value.

An optional argument #:datadef can be provided, which consumes mock data from the datadef definition one by one.

Example tests:
> (require rackunit
           db
           datadef)
> (db-funcs-init dtb)
> (test-case
      "Testing list of hash and empty list return type"
      (define-datadef test
                      '((column1 _ (val1 val2)) (column2 _ (val3 val4)))
                      #:ret-type hash
                      #:from "table")
      (with-mock-data ((datadef:test ((0 1) #f))
                       (dtb-query-rows ((#(val1 val2 val3)) ()) (0 1)))
        (check-equal? (datadef:test->result)
                      `(,#hash((column1 . val1)
                               (column2 . val3))
                        ,#hash((column1 . val2)
                               (column2 . val4))))
        (check-equal? (datadef:test->result)
                      '())
        (check-equal? (dtb-query-rows "SELECT * FROM table")
                      '(#(val1 val2 val3)))
        (check-equal? (dtb-query-rows "SELECT * FROM another_table")
                      '()))
      (with-mock-data #:datadef
        (check-equal? (datadef:test->result)
                      `(,#hash((column1 . val1)
                               (column2 . val3))))))

syntax

(db-funcs-init prefix
                     [#:exn-fail-thunk exn-fail-thunk])
 
  prefix : any/c
  exn-fail-thunk : (-> exn? (listof vector?))
Creates wrappers around db query functions with the provided prefix. For example, if the user provides a prefix dtb, functions such as query-rows will be wrapped and called dtb-query-rows. The wrapped functions provide some benefits, such as handling the database connection and deciding if data should be mocked.