From 57c09c13e505833a1741d5af8e697b87d96370a4 Mon Sep 17 00:00:00 2001 From: aryehb <49538279+aryehb@users.noreply.github.com> Date: Wed, 15 Jun 2022 12:31:18 -0400 Subject: [PATCH] Document callback handlers for response and responseOnce (#31) --- README.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 47efe26..716e459 100644 --- a/README.md +++ b/README.md @@ -105,22 +105,35 @@ Each one of `on` methods (`select`, `insert`,`update`, `delete`, `any`) are acce You can specify the db response by calling: -1. `response(dbData)` - will register a permanent query handler with the same response value +1. `response(data: T | ((rawQuery: RawQuery) => (T | Promise)))` - This will register a permanent query handler. + + If a value is provided, it will be returned directly. + If a callback is passed, it will be called with the `RawQuery` and should return a value for the tracker to return. ```ts tracker.on.select('select * from users where `id`=?').response([{ id: 1, name: 'foo' }]); ``` + ```ts + tracker.on.select('select * from users where `id`=?').response(rawQuery => [{ id: 1, name: 'foo' }]); + ``` + +2. `responseOnce(data: T | ((rawQuery: RawQuery) => (T | Promise)))`- This will register a one-time query handler, which will be removed from handlers list after the first usage. + + If a value is provided, it will be returned directly. If a callback is passed, it will be called with the `RawQuery` and should return a value for the tracker to return. -2. `responseOnce(dbData)` - will register a one-time query handler, after the first usage it will - be removed from handlers list. ```ts tracker.on.select('select * from users where `id`=?').responseOnce([{ id: 1, name: 'foo' }]); ``` + ```ts + tracker.on.select('select * from users where `id`=?').responseOnce(rawQuery => Promise.resolve([{ id: 1, name: 'foo' }])); + ``` + 3. `simulateError(errorMessage: string)` - will register a permanent failure handler for the matched query ```ts tracker.on.select('select * from users where `id`=?').simulateError('Connection lost'); ``` + 4. `simulateErrorOnce(errorMessage: string)` - will register a one-time failure handler, after the first usage it will be removed from handlers list. ```ts