UNPKG

slonik

Version:

A Node.js PostgreSQL client with strict types, detailed logging and assertions.

39 lines 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const createPool_1 = require("../factories/createPool"); const createTestRunner_1 = require("../helpers.test/createTestRunner"); const errors_1 = require("@slonik/errors"); const pg_driver_1 = require("@slonik/pg-driver"); const sql_tag_1 = require("@slonik/sql-tag"); const driverFactory = (0, pg_driver_1.createPgDriverFactory)(); const { test } = (0, createTestRunner_1.createTestRunner)(driverFactory, 'pg'); const sql = (0, sql_tag_1.createSqlTag)(); test('returns the query results rows', async (t) => { const pool = await (0, createPool_1.createPool)(t.context.dsn, { driverFactory, }); const result = await pool.many(sql.unsafe ` SELECT * FROM (VALUES (1), (2)) as t(id) `); t.deepEqual(result, [ { id: 1, }, { id: 2, }, ]); }); test('throws an error if no rows are returned', async (t) => { const pool = await (0, createPool_1.createPool)(t.context.dsn, { driverFactory, }); const error = await t.throwsAsync(pool.many(sql.unsafe ` SELECT * FROM (VALUES (1)) as t(id) WHERE false `)); t.true(error instanceof errors_1.NotFoundError); }); //# sourceMappingURL=many.test.js.map