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

19 lines (18 loc) 701 B
export 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); } } } }; }