pgsql-seed 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +80 -38
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -16,33 +16,83 @@
16
16
  </a>
17
17
  </p>
18
18
 
19
- PostgreSQL seeding utilities with pgpm integration - batteries included.
20
-
21
- This package re-exports everything from [`pg-seed`](https://www.npmjs.com/package/pg-seed) and adds pgpm deployment functionality.
19
+ PostgreSQL seeding utilities for CSV, JSON, SQL data loading, and pgpm deployment.
22
20
 
23
21
  ## Installation
24
22
 
25
23
  ```bash
26
24
  npm install pgsql-seed
27
- # or
28
- pnpm add pgsql-seed
29
25
  ```
30
26
 
31
27
  ## Usage
32
28
 
33
- ### All pg-seed utilities are available
29
+ ### CSV Loading (COPY protocol)
34
30
 
35
31
  ```typescript
36
- import {
37
- loadCsv, loadCsvMap, exportCsv, // CSV utilities
38
- insertJson, insertJsonMap, // JSON utilities
39
- loadSql, loadSqlFiles, execSql // SQL utilities
40
- } from 'pgsql-seed';
32
+ import { Client } from 'pg';
33
+ import { loadCsv, loadCsvMap, exportCsv } from 'pgsql-seed';
34
+
35
+ const client = new Client();
36
+ await client.connect();
37
+
38
+ // Load a single CSV file
39
+ await loadCsv(client, 'users', './data/users.csv');
40
+
41
+ // Load multiple CSV files
42
+ await loadCsvMap(client, {
43
+ 'users': './data/users.csv',
44
+ 'orders': './data/orders.csv'
45
+ });
46
+
47
+ // Export a table to CSV
48
+ await exportCsv(client, 'users', './backup/users.csv');
41
49
  ```
42
50
 
43
- See the [pg-seed documentation](https://www.npmjs.com/package/pg-seed) for details on these utilities.
51
+ ### JSON Insertion
52
+
53
+ ```typescript
54
+ import { Client } from 'pg';
55
+ import { insertJson, insertJsonMap } from 'pgsql-seed';
56
+
57
+ const client = new Client();
58
+ await client.connect();
59
+
60
+ // Insert rows into a single table
61
+ await insertJson(client, 'users', [
62
+ { name: 'Alice', email: 'alice@example.com' },
63
+ { name: 'Bob', email: 'bob@example.com' }
64
+ ]);
65
+
66
+ // Insert rows into multiple tables
67
+ await insertJsonMap(client, {
68
+ 'users': [{ name: 'Alice', email: 'alice@example.com' }],
69
+ 'orders': [{ user_id: 1, total: 99.99 }]
70
+ });
71
+ ```
72
+
73
+ ### SQL File Execution
74
+
75
+ ```typescript
76
+ import { Client } from 'pg';
77
+ import { loadSql, loadSqlFiles, execSql } from 'pgsql-seed';
78
+
79
+ const client = new Client();
80
+ await client.connect();
81
+
82
+ // Execute a single SQL file
83
+ await loadSql(client, './migrations/001-schema.sql');
84
+
85
+ // Execute multiple SQL files
86
+ await loadSqlFiles(client, [
87
+ './migrations/001-schema.sql',
88
+ './migrations/002-data.sql'
89
+ ]);
90
+
91
+ // Execute a SQL string with parameters
92
+ await execSql(client, 'INSERT INTO users (name) VALUES ($1)', ['Alice']);
93
+ ```
44
94
 
45
- ### pgpm Integration
95
+ ### pgpm Deployment
46
96
 
47
97
  Deploy pgpm packages directly from your code:
48
98
 
@@ -67,10 +117,19 @@ await deployPgpm(config, '/path/to/package');
67
117
  await deployPgpm(config, undefined, true);
68
118
  ```
69
119
 
70
- ## When to use pg-seed vs pgsql-seed
120
+ ## Client Compatibility
121
+
122
+ All functions accept either a raw `pg.Client`/`pg.PoolClient` or any wrapper object that exposes a `.client` property containing the underlying pg client. This makes it compatible with testing utilities like `PgTestClient`.
123
+
124
+ ```typescript
125
+ // Works with raw pg.Client
126
+ const client = new Client();
127
+ await loadCsv(client, 'users', './data/users.csv');
71
128
 
72
- - Use **`pg-seed`** if you only need CSV/JSON/SQL seeding and want a lightweight package with no pgpm dependency
73
- - Use **`pgsql-seed`** if you need pgpm deployment functionality or want a single package with all seeding utilities
129
+ // Works with wrappers that have a .client property
130
+ const testClient = new PgTestClient(config);
131
+ await loadCsv(testClient, 'users', './data/users.csv');
132
+ ```
74
133
 
75
134
  ---
76
135
 
@@ -99,9 +158,14 @@ Common issues and solutions for pgpm, PostgreSQL, and testing.
99
158
 
100
159
  ## Related Constructive Tooling
101
160
 
161
+ ### 📦 Package Management
162
+
163
+ * [pgpm](https://github.com/constructive-io/constructive/tree/main/pgpm/pgpm): **🖥️ PostgreSQL Package Manager** for modular Postgres development. Works with database workspaces, scaffolding, migrations, seeding, and installing database packages.
164
+
102
165
  ### 🧪 Testing
103
166
 
104
167
  * [pgsql-test](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-test): **📊 Isolated testing environments** with per-test transaction rollbacks—ideal for integration tests, complex migrations, and RLS simulation.
168
+ * [pgsql-seed](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-seed): **🌱 PostgreSQL seeding utilities** for CSV, JSON, SQL data loading, and pgpm deployment.
105
169
  * [supabase-test](https://github.com/constructive-io/constructive/tree/main/postgres/supabase-test): **🧪 Supabase-native test harness** preconfigured for the local Supabase stack—per-test rollbacks, JWT/role context helpers, and CI/GitHub Actions ready.
106
170
  * [graphile-test](https://github.com/constructive-io/constructive/tree/main/graphile/graphile-test): **🔐 Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts.
107
171
  * [pg-query-context](https://github.com/constructive-io/constructive/tree/main/postgres/pg-query-context): **🔒 Session context injection** to add session-local context (e.g., `SET LOCAL`) into queries—ideal for setting `role`, `jwt.claims`, and other session settings.
@@ -115,28 +179,6 @@ Common issues and solutions for pgpm, PostgreSQL, and testing.
115
179
  * [@pgsql/types](https://www.npmjs.com/package/@pgsql/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
116
180
  * [@pgsql/utils](https://www.npmjs.com/package/@pgsql/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
117
181
 
118
- ### 🚀 API & Dev Tools
119
-
120
- * [@constructive-io/graphql-server](https://github.com/constructive-io/constructive/tree/main/graphql/server): **⚡ Express-based API server** powered by PostGraphile to expose a secure, scalable GraphQL API over your Postgres database.
121
- * [@constructive-io/graphql-explorer](https://github.com/constructive-io/constructive/tree/main/graphql/explorer): **🔎 Visual API explorer** with GraphiQL for browsing across all databases and schemas—useful for debugging, documentation, and API prototyping.
122
-
123
- ### 🔁 Streaming & Uploads
124
-
125
- * [etag-hash](https://github.com/constructive-io/constructive/tree/main/streaming/etag-hash): **🏷️ S3-compatible ETags** created by streaming and hashing file uploads in chunks.
126
- * [etag-stream](https://github.com/constructive-io/constructive/tree/main/streaming/etag-stream): **🔄 ETag computation** via Node stream transformer during upload or transfer.
127
- * [uuid-hash](https://github.com/constructive-io/constructive/tree/main/streaming/uuid-hash): **🆔 Deterministic UUIDs** generated from hashed content, great for deduplication and asset referencing.
128
- * [uuid-stream](https://github.com/constructive-io/constructive/tree/main/streaming/uuid-stream): **🌊 Streaming UUID generation** based on piped file content—ideal for upload pipelines.
129
- * [@constructive-io/s3-streamer](https://github.com/constructive-io/constructive/tree/main/streaming/s3-streamer): **📤 Direct S3 streaming** for large files with support for metadata injection and content validation.
130
- * [@constructive-io/upload-names](https://github.com/constructive-io/constructive/tree/main/streaming/upload-names): **📂 Collision-resistant filenames** utility for structured and unique file names for uploads.
131
-
132
- ### 🧰 CLI & Codegen
133
-
134
- * [pgpm](https://github.com/constructive-io/constructive/tree/main/pgpm/pgpm): **🖥️ PostgreSQL Package Manager** for modular Postgres development. Works with database workspaces, scaffolding, migrations, seeding, and installing database packages.
135
- * [@constructive-io/cli](https://github.com/constructive-io/constructive/tree/main/packages/cli): **🖥️ Command-line toolkit** for managing Constructive projects—supports database scaffolding, migrations, seeding, code generation, and automation.
136
- * [@constructive-io/graphql-codegen](https://github.com/constructive-io/constructive/tree/main/graphql/codegen): **✨ GraphQL code generation** (types, operations, SDK) from schema/endpoint introspection.
137
- * [@constructive-io/query-builder](https://github.com/constructive-io/constructive/tree/main/packages/query-builder): **🏗️ SQL constructor** providing a robust TypeScript-based query builder for dynamic generation of `SELECT`, `INSERT`, `UPDATE`, `DELETE`, and stored procedure calls—supports advanced SQL features like `JOIN`, `GROUP BY`, and schema-qualified queries.
138
- * [@constructive-io/graphql-query](https://github.com/constructive-io/constructive/tree/main/graphql/query): **🧩 Fluent GraphQL builder** for PostGraphile schemas. ⚡ Schema-aware via introspection, 🧩 composable and ergonomic for building deeply nested queries.
139
-
140
182
  ## Credits
141
183
 
142
184
  **🛠 Built by the [Constructive](https://constructive.io) team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgsql-seed",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "PostgreSQL seeding utilities with pgpm integration - batteries included",
6
6
  "main": "index.js",
@@ -46,11 +46,11 @@
46
46
  "makage": "^0.1.9"
47
47
  },
48
48
  "dependencies": {
49
- "@pgpmjs/core": "^4.4.0",
49
+ "@pgpmjs/core": "^4.5.1",
50
50
  "@pgpmjs/env": "^2.8.11",
51
51
  "pg": "^8.16.3",
52
52
  "pg-env": "^1.2.4",
53
- "pg-seed": "^0.2.0"
53
+ "pg-seed": "^0.2.1"
54
54
  },
55
- "gitHead": "bda56442f70c77c98276bc7bab0450308c975df8"
55
+ "gitHead": "6883e3b93da28078483bc6aa25862613ef4405b2"
56
56
  }