All files / dist/src/driver-integrations pgp.js

44% Statements 11/25
0% Branches 0/9
8.33% Functions 1/12
44% Lines 11/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58  1x 1x 1x 6x                     6x           6x           6x           6x           6x           6x                     1x  
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createForPGP = void 0;
const createForPGP = ({ core, db, logError }) => {
    const defaultErrorHandler = (err) => {
        if (!(err.name === 'QueryResultError')) {
            if (logError) {
                logError(err);
            }
        }
        throw err;
    };
    /* ------------------------------------------------------------------------*/
    /* Query functions --------------------------------------------------------*/
    /* ------------------------------------------------------------------------*/
    const one = (query, values, errorHandler = defaultErrorHandler) => {
        return db
            .many(query, values)
            .then((rows) => core.createOneFromDatabase(rows))
            .catch(errorHandler);
    };
    const oneOrNone = (query, values, errorHandler = defaultErrorHandler) => {
        return db
            .any(query, values)
            .then((rows) => core.createOneOrNoneFromDatabase(rows))
            .catch(errorHandler);
    };
    const many = (query, values, errorHandler = defaultErrorHandler) => {
        return db
            .any(query, values)
            .then((rows) => core.createManyFromDatabase(rows))
            .catch(errorHandler);
    };
    const any = (query, values, errorHandler = defaultErrorHandler) => {
        return db
            .result(query, values)
            .then((result) => core.createAnyFromDatabase(result.rows, result.fields[0].name.split('#')[0]))
            .catch(errorHandler);
    };
    const none = (query, values, errorHandler = defaultErrorHandler) => {
        return db
            .none(query, values)
            .then(() => null)
            .catch(errorHandler);
    };
    return Object.assign({}, core, {
        // Query Functions
        one,
        oneOrNone,
        many,
        any,
        none,
        // provide direct access to db
        db
    });
};
exports.createForPGP = createForPGP;