UNPKG

pgsql-test

Version:

pgsql-test offers isolated, role-aware, and rollback-friendly PostgreSQL environments for integration tests — giving developers realistic test coverage without external state pollution

22 lines (21 loc) 792 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.json = json; function json(data) { return { async seed(ctx) { const { pg } = ctx; for (const [table, rows] of Object.entries(data)) { if (!Array.isArray(rows) || rows.length === 0) continue; const columns = Object.keys(rows[0]); const placeholders = columns.map((_, i) => `$${i + 1}`).join(', '); const sql = `INSERT INTO ${table} (${columns.join(', ')}) VALUES (${placeholders})`; for (const row of rows) { const values = columns.map((c) => row[c]); await pg.query(sql, values); } } } }; }