pgsql-client 2.0.0 → 2.0.2
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.
- package/README.md +53 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -123,6 +123,59 @@ await client.close();
|
|
|
123
123
|
- `clearContext()` - Clear context and reset to anonymous
|
|
124
124
|
- `close()` - Close connection
|
|
125
125
|
|
|
126
|
+
### Ephemeral Databases
|
|
127
|
+
|
|
128
|
+
Create temporary databases for testing, code generation, or other ephemeral use cases:
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import { createEphemeralDb } from 'pgsql-client';
|
|
132
|
+
|
|
133
|
+
// Create a temporary database with a unique UUID-based name
|
|
134
|
+
const { name, config, admin, teardown } = createEphemeralDb();
|
|
135
|
+
|
|
136
|
+
// Use the database
|
|
137
|
+
const pool = new Pool(config);
|
|
138
|
+
await pool.query('SELECT 1');
|
|
139
|
+
await pool.end();
|
|
140
|
+
|
|
141
|
+
// Clean up when done
|
|
142
|
+
teardown();
|
|
143
|
+
|
|
144
|
+
// Or keep for debugging
|
|
145
|
+
teardown({ keepDb: true });
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
#### Options
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
const { config, teardown } = createEphemeralDb({
|
|
152
|
+
prefix: 'test_', // Database name prefix (default: 'ephemeral_')
|
|
153
|
+
extensions: ['uuid-ossp'], // PostgreSQL extensions to install
|
|
154
|
+
baseConfig: { // Override connection settings
|
|
155
|
+
host: 'localhost',
|
|
156
|
+
port: 5432,
|
|
157
|
+
user: 'postgres',
|
|
158
|
+
password: 'password'
|
|
159
|
+
},
|
|
160
|
+
verbose: true // Enable logging
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
#### Return Value
|
|
165
|
+
|
|
166
|
+
- `name` - The generated database name (e.g., `ephemeral_a1b2c3d4_...`)
|
|
167
|
+
- `config` - Full PostgreSQL configuration for connecting
|
|
168
|
+
- `admin` - DbAdmin instance for additional operations
|
|
169
|
+
- `teardown(opts?)` - Function to drop the database (pass `{ keepDb: true }` to preserve)
|
|
170
|
+
|
|
171
|
+
#### Use Cases
|
|
172
|
+
|
|
173
|
+
Ephemeral databases are useful for:
|
|
174
|
+
- **Code generation**: Generate types from a temporary schema
|
|
175
|
+
- **Integration tests**: Isolated database per test suite
|
|
176
|
+
- **CI pipelines**: Clean database state for each run
|
|
177
|
+
- **Local development**: Experiment without affecting shared databases
|
|
178
|
+
|
|
126
179
|
## License
|
|
127
180
|
|
|
128
181
|
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pgsql-client",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "PostgreSQL client utilities with query helpers, RLS context management, and database administration",
|
|
6
6
|
"main": "index.js",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"makage": "^0.1.10"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@pgpmjs/core": "^5.0.
|
|
48
|
+
"@pgpmjs/core": "^5.0.1",
|
|
49
49
|
"@pgpmjs/logger": "^2.0.0",
|
|
50
50
|
"@pgpmjs/types": "^2.15.0",
|
|
51
51
|
"pg": "^8.17.1",
|
|
52
52
|
"pg-env": "^1.3.0"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "532b9bae03b2a77fd5dff4981ad2a775bb27397a"
|
|
55
55
|
}
|