UNPKG

slonik-trpc

Version:
30 lines (29 loc) 976 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useSlowQueryPlugin = void 0; const defaultLogSlowQuery = (options) => { console.log(`Slow query: ${options.query.sql} (${options.duration}ms)`); }; const useSlowQueryPlugin = ({ slowQueryThreshold = 1000, callback = defaultLogSlowQuery } = {}) => { const onLoad = (loadOptions) => { const start = Date.now(); return { onLoadDone(options) { const duration = Date.now() - start; if (duration >= slowQueryThreshold) { callback({ query: loadOptions.query, duration, result: options.result, args: loadOptions.args, }); } }, }; }; return { onLoad, onLoadPagination: onLoad, }; }; exports.useSlowQueryPlugin = useSlowQueryPlugin;