Registry / database / pg-seed

pg-seed

JSON →
library0.15.0jsnpmunverified

PostgreSQL seeding utilities for CSV, JSON, and SQL data loading. Version 0.15.0, stable, actively maintained. Uses COPY streaming for high-performance inserts. Supports multiple data formats and schema initialization. Differentiated by streaming approach vs row-by-row inserts.

npm install pg-seed
INSTALL
IMPORT
SIG · PG-SEED
P
pg-seed
databasejavascriptv0.15.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

seed
import { seed } from 'pg-seed'
const seed = require('pg-seed')
ESM-only since v0.15.0
Seeder
import { Seeder } from 'pg-seed'
Class for programmatic seeding
types
import type { SeedOptions } from 'pg-seed'
import { SeedOptions } from 'pg-seed'
TypeScript type imports

Shows basic usage of seed function with schema and CSV data

import { seed } from 'pg-seed'; import pg from 'pg'; const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL ?? '' }); async function run() { try { await seed({ client: pool, schema: ['CREATE TABLE IF NOT EXISTS users (id SERIAL PRIMARY KEY, name TEXT);'], data: [ { table: 'users', format: 'csv', data: '1,Alice\n2,Bob', columns: ['id', 'name'] } ] }); console.log('Seeding complete'); } catch (err) { console.error(err); } finally { await pool.end(); } } run();
Debug
Known issues
breakingESM-only from v0.15.0, require() not supported
fix
Use import statements or dynamic import() in CommonJS projects
affects: >=0.15.0
deprecatedseedFromFile and seedFromStream deprecated in favor of seed()
fix
Use seed() with data array
affects: >=0.14.0
gotchaclient parameter must be a pg.Pool, not a client instance
fix
Pass a Pool instance to seed()
affects: >=0.15.0
gotchaCSV data must not include a header row unless columns option is omitted
fix
Provide columns array matching CSV columns order
affects: >=0.10.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'query')
Client or pool not provided correctly
fix
Ensure you pass a pg.Pool instance as the client option
Error: ESM-only package. Use import instead of require.
Using require() with ESM-only version
fix
Switch to import syntax or update to older version
Error: column "id" does not exist
CSV columns don't match table schema
fix
Check that CSV columns match table column names and include the correct order
Upgrade
Version history
0.15.0latest on npm
Audit
Dependencies
pgrequiredPostgreSQL client for database connections
Agent activity
5 hits · last 30 days
node
4
Resources
pg-seed — npm install pg-seed · libregistry