pg-cache 1.0.0 → 1.0.1

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 CHANGED
@@ -34,10 +34,10 @@ npm install pg-cache
34
34
  ### Basic Pool Management
35
35
 
36
36
  ```typescript
37
- import { pgCache, getRootPgPool } from 'pg-cache';
37
+ import { pgCache, getPgPool } from 'pg-cache';
38
38
 
39
39
  // Get or create a cached pool
40
- const pool = getRootPgPool({
40
+ const pool = getPgPool({
41
41
  host: 'localhost',
42
42
  port: 5432,
43
43
  database: 'mydb',
@@ -49,7 +49,7 @@ const pool = getRootPgPool({
49
49
  const result = await pool.query('SELECT NOW()');
50
50
 
51
51
  // Pool is automatically cached and reused
52
- const samePool = getRootPgPool({ database: 'mydb' }); // Returns cached pool
52
+ const samePool = getPgPool({ database: 'mydb' }); // Returns cached pool
53
53
  ```
54
54
 
55
55
  ### Direct Cache Access
@@ -123,7 +123,7 @@ The main PostgreSQL pool cache instance.
123
123
  - `clear(): void` - Remove and dispose all pools
124
124
  - `registerCleanupCallback(callback: (key: string) => void): () => void` - Register a cleanup callback
125
125
 
126
- ### getRootPgPool(config: Partial<PgConfig>): Pool
126
+ ### getPgPool(config: Partial<PgConfig>): Pool
127
127
 
128
128
  Get or create a cached PostgreSQL pool using the provided configuration.
129
129
 
package/esm/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // Main exports from pg-cache package
2
2
  export { pgCache, PgPoolCacheManager, close, teardownPgPools } from './lru';
3
- export { getRootPgPool } from './pg';
3
+ export { getPgPool } from './pg';
package/esm/pg.js CHANGED
@@ -2,7 +2,7 @@ import pg from 'pg';
2
2
  import { pgCache } from './lru';
3
3
  import { getPgEnvOptions } from 'pg-env';
4
4
  const getDbString = (user, password, host, port, database) => `postgres://${user}:${password}@${host}:${port}/${database}`;
5
- export const getRootPgPool = (pgConfig) => {
5
+ export const getPgPool = (pgConfig) => {
6
6
  const config = getPgEnvOptions(pgConfig);
7
7
  const { user, password, host, port, database, } = config;
8
8
  if (pgCache.has(database)) {
package/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { pgCache, PgPoolCacheManager, close, teardownPgPools } from './lru';
2
- export { getRootPgPool } from './pg';
2
+ export { getPgPool } from './pg';
3
3
  export type { PoolCleanupCallback } from './lru';
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRootPgPool = exports.teardownPgPools = exports.PgPoolCacheManager = exports.pgCache = void 0;
3
+ exports.getPgPool = exports.teardownPgPools = exports.PgPoolCacheManager = exports.pgCache = void 0;
4
4
  // Main exports from pg-cache package
5
5
  var lru_1 = require("./lru");
6
6
  Object.defineProperty(exports, "pgCache", { enumerable: true, get: function () { return lru_1.pgCache; } });
@@ -8,4 +8,4 @@ Object.defineProperty(exports, "PgPoolCacheManager", { enumerable: true, get: fu
8
8
  Object.defineProperty(exports, "close", { enumerable: true, get: function () { return lru_1.close; } });
9
9
  Object.defineProperty(exports, "teardownPgPools", { enumerable: true, get: function () { return lru_1.teardownPgPools; } });
10
10
  var pg_1 = require("./pg");
11
- Object.defineProperty(exports, "getRootPgPool", { enumerable: true, get: function () { return pg_1.getRootPgPool; } });
11
+ Object.defineProperty(exports, "getPgPool", { enumerable: true, get: function () { return pg_1.getPgPool; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-cache",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "author": "Dan Lynch <pyramation@gmail.com>",
5
5
  "description": "PostgreSQL connection pool LRU cache manager",
6
6
  "main": "index.js",
@@ -30,11 +30,11 @@
30
30
  "test:watch": "jest --watch"
31
31
  },
32
32
  "dependencies": {
33
- "@launchql/logger": "^1.0.0",
34
- "@launchql/types": "^2.1.12",
33
+ "@launchql/logger": "^1.0.1",
34
+ "@launchql/types": "^2.1.13",
35
35
  "lru-cache": "^11.1.0",
36
- "pg-env": "^1.0.0",
37
- "pg": "^8.16.0"
36
+ "pg": "^8.16.0",
37
+ "pg-env": "^1.0.1"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/pg": "^8.15.2"
@@ -47,5 +47,6 @@
47
47
  "lru",
48
48
  "connection",
49
49
  "launchql"
50
- ]
50
+ ],
51
+ "gitHead": "835a2e84ed84edab5bea8f5954d9dfeb657beb03"
51
52
  }
package/pg.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import pg from 'pg';
2
2
  import { PgConfig } from 'pg-env';
3
- export declare const getRootPgPool: (pgConfig: Partial<PgConfig>) => pg.Pool;
3
+ export declare const getPgPool: (pgConfig: Partial<PgConfig>) => pg.Pool;
package/pg.js CHANGED
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getRootPgPool = void 0;
6
+ exports.getPgPool = void 0;
7
7
  const pg_1 = __importDefault(require("pg"));
8
8
  const lru_1 = require("./lru");
9
9
  const pg_env_1 = require("pg-env");
10
10
  const getDbString = (user, password, host, port, database) => `postgres://${user}:${password}@${host}:${port}/${database}`;
11
- const getRootPgPool = (pgConfig) => {
11
+ const getPgPool = (pgConfig) => {
12
12
  const config = (0, pg_env_1.getPgEnvOptions)(pgConfig);
13
13
  const { user, password, host, port, database, } = config;
14
14
  if (lru_1.pgCache.has(database)) {
@@ -21,4 +21,4 @@ const getRootPgPool = (pgConfig) => {
21
21
  lru_1.pgCache.set(database, pgPool);
22
22
  return pgPool;
23
23
  };
24
- exports.getRootPgPool = getRootPgPool;
24
+ exports.getPgPool = getPgPool;
package/dist/README.md DELETED
@@ -1,187 +0,0 @@
1
- # pg-cache
2
-
3
- <p align="center" width="100%">
4
- <img height="250" src="https://raw.githubusercontent.com/launchql/launchql/refs/heads/main/assets/outline-logo.svg" />
5
- </p>
6
-
7
- <p align="center" width="100%">
8
- <a href="https://github.com/launchql/launchql/actions/workflows/run-tests.yaml">
9
- <img height="20" src="https://github.com/launchql/launchql/actions/workflows/run-tests.yaml/badge.svg" />
10
- </a>
11
- <a href="https://github.com/launchql/launchql/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
12
- <a href="https://www.npmjs.com/package/@launchql/server-utils"><img height="20" src="https://img.shields.io/github/package-json/v/launchql/launchql?filename=packages%2Fserver-utils%2Fpackage.json"/></a>
13
- </p>
14
-
15
- PostgreSQL connection pool LRU cache manager with zero PostGraphile dependencies.
16
-
17
- ## Installation
18
-
19
- ```bash
20
- npm install pg-cache
21
- ```
22
-
23
- ## Features
24
-
25
- - LRU cache for PostgreSQL connection pools
26
- - Automatic pool cleanup and disposal
27
- - Extensible cleanup callback system
28
- - Service cache for general use
29
- - Graceful shutdown handling
30
- - TypeScript support
31
-
32
- ## Usage
33
-
34
- ### Basic Pool Management
35
-
36
- ```typescript
37
- import { pgCache, getRootPgPool } from 'pg-cache';
38
-
39
- // Get or create a cached pool
40
- const pool = getRootPgPool({
41
- host: 'localhost',
42
- port: 5432,
43
- database: 'mydb',
44
- user: 'postgres',
45
- password: 'password'
46
- });
47
-
48
- // Use the pool
49
- const result = await pool.query('SELECT NOW()');
50
-
51
- // Pool is automatically cached and reused
52
- const samePool = getRootPgPool({ database: 'mydb' }); // Returns cached pool
53
- ```
54
-
55
- ### Direct Cache Access
56
-
57
- ```typescript
58
- import { pgCache } from 'pg-cache';
59
- import { Pool } from 'pg';
60
-
61
- // Create and cache a pool manually
62
- const pool = new Pool({ connectionString: 'postgres://...' });
63
- pgCache.set('my-pool-key', pool);
64
-
65
- // Retrieve it later
66
- const cachedPool = pgCache.get('my-pool-key');
67
-
68
- // Remove from cache (also disposes the pool)
69
- pgCache.delete('my-pool-key');
70
- ```
71
-
72
- ### Cleanup Callbacks
73
-
74
- Register callbacks to be notified when pools are disposed:
75
-
76
- ```typescript
77
- import { pgCache } from 'pg-cache';
78
-
79
- // Register a cleanup callback
80
- const unregister = pgCache.registerCleanupCallback((poolKey: string) => {
81
- console.log(`Pool ${poolKey} was disposed`);
82
- // Clean up any resources associated with this pool
83
- });
84
-
85
- // Later, unregister if needed
86
- unregister();
87
- ```
88
-
89
- ### Service Cache
90
-
91
- A general-purpose cache is also provided:
92
-
93
- ```typescript
94
- import { svcCache } from 'pg-cache';
95
-
96
- // Cache any service or object
97
- svcCache.set('my-service', myServiceInstance);
98
- const service = svcCache.get('my-service');
99
- ```
100
-
101
- ### Graceful Shutdown
102
-
103
- ```typescript
104
- import { close, teardownPgPools } from 'pg-cache';
105
-
106
- // In your shutdown handler
107
- process.on('SIGTERM', async () => {
108
- await close(); // or teardownPgPools()
109
- process.exit(0);
110
- });
111
- ```
112
-
113
- ## API Reference
114
-
115
- ### pgCache
116
-
117
- The main PostgreSQL pool cache instance.
118
-
119
- - `get(key: string): Pool | undefined` - Get a cached pool
120
- - `set(key: string, pool: Pool): void` - Cache a pool
121
- - `has(key: string): boolean` - Check if a pool is cached
122
- - `delete(key: string): void` - Remove and dispose a pool
123
- - `clear(): void` - Remove and dispose all pools
124
- - `registerCleanupCallback(callback: (key: string) => void): () => void` - Register a cleanup callback
125
-
126
- ### getRootPgPool(config: Partial<PgConfig>): Pool
127
-
128
- Get or create a cached PostgreSQL pool using the provided configuration.
129
-
130
- ### svcCache
131
-
132
- A general-purpose LRU cache for services and objects.
133
-
134
- ### close() / teardownPgPools()
135
-
136
- Gracefully close all cached pools and wait for disposal.
137
-
138
- ## Integration with Other Packages
139
-
140
- This package is designed to be extended. For example, `@launchql/graphile-cache` uses the cleanup callback system to automatically clean up PostGraphile instances when their associated pools are disposed.
141
-
142
-
143
- ## Related LaunchQL Tooling
144
-
145
- ### 🧪 Testing
146
-
147
- * [launchql/pgsql-test](https://github.com/launchql/launchql/tree/main/packages/pgsql-test): **📊 Isolated testing environments** with per-test transaction rollbacks—ideal for integration tests, complex migrations, and RLS simulation.
148
- * [launchql/graphile-test](https://github.com/launchql/launchql/tree/main/packages/graphile-test): **🔐 Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts.
149
- * [launchql/pg-query-context](https://github.com/launchql/launchql/tree/main/packages/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.
150
-
151
- ### 🧠 Parsing & AST
152
-
153
- * [launchql/pgsql-parser](https://github.com/launchql/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
154
- * [launchql/libpg-query-node](https://github.com/launchql/libpg-query-node): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
155
- * [launchql/pg-proto-parser](https://github.com/launchql/pg-proto-parser): **📦 Protobuf parser** for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
156
- * [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums): **🏷️ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic.
157
- * [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
158
- * [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
159
- * [launchql/pg-ast](https://github.com/launchql/launchql/tree/main/packages/pg-ast): **🔍 Low-level AST tools** and transformations for Postgres query structures.
160
-
161
- ### 🚀 API & Dev Tools
162
-
163
- * [launchql/server](https://github.com/launchql/launchql/tree/main/packages/server): **⚡ Express-based API server** powered by PostGraphile to expose a secure, scalable GraphQL API over your Postgres database.
164
- * [launchql/explorer](https://github.com/launchql/launchql/tree/main/packages/explorer): **🔎 Visual API explorer** with GraphiQL for browsing across all databases and schemas—useful for debugging, documentation, and API prototyping.
165
-
166
- ### 🔁 Streaming & Uploads
167
-
168
- * [launchql/s3-streamer](https://github.com/launchql/launchql/tree/main/packages/s3-streamer): **📤 Direct S3 streaming** for large files with support for metadata injection and content validation.
169
- * [launchql/etag-hash](https://github.com/launchql/launchql/tree/main/packages/etag-hash): **🏷️ S3-compatible ETags** created by streaming and hashing file uploads in chunks.
170
- * [launchql/etag-stream](https://github.com/launchql/launchql/tree/main/packages/etag-stream): **🔄 ETag computation** via Node stream transformer during upload or transfer.
171
- * [launchql/uuid-hash](https://github.com/launchql/launchql/tree/main/packages/uuid-hash): **🆔 Deterministic UUIDs** generated from hashed content, great for deduplication and asset referencing.
172
- * [launchql/uuid-stream](https://github.com/launchql/launchql/tree/main/packages/uuid-stream): **🌊 Streaming UUID generation** based on piped file content—ideal for upload pipelines.
173
- * [launchql/upload-names](https://github.com/launchql/launchql/tree/main/packages/upload-names): **📂 Collision-resistant filenames** utility for structured and unique file names for uploads.
174
-
175
- ### 🧰 CLI & Codegen
176
-
177
- * [@launchql/cli](https://github.com/launchql/launchql/tree/main/packages/cli): **🖥️ Command-line toolkit** for managing LaunchQL projects—supports database scaffolding, migrations, seeding, code generation, and automation.
178
- * [launchql/launchql-gen](https://github.com/launchql/launchql/tree/main/packages/launchql-gen): **✨ Auto-generated GraphQL** mutations and queries dynamically built from introspected schema data.
179
- * [@launchql/query-builder](https://github.com/launchql/launchql/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.
180
- * [@launchql/query](https://github.com/launchql/launchql/tree/main/packages/query): **🧩 Fluent GraphQL builder** for PostGraphile schemas. ⚡ Schema-aware via introspection, 🧩 composable and ergonomic for building deeply nested queries.
181
-
182
- ## Disclaimer
183
-
184
- AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
185
-
186
- No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
187
-
package/dist/package.json DELETED
@@ -1,51 +0,0 @@
1
- {
2
- "name": "pg-cache",
3
- "version": "1.0.0",
4
- "author": "Dan Lynch <pyramation@gmail.com>",
5
- "description": "PostgreSQL connection pool LRU cache manager",
6
- "main": "index.js",
7
- "module": "esm/index.js",
8
- "types": "index.d.ts",
9
- "homepage": "https://github.com/launchql/launchql",
10
- "license": "MIT",
11
- "publishConfig": {
12
- "access": "public",
13
- "directory": "dist"
14
- },
15
- "repository": {
16
- "type": "git",
17
- "url": "https://github.com/launchql/launchql"
18
- },
19
- "bugs": {
20
- "url": "https://github.com/launchql/launchql/issues"
21
- },
22
- "scripts": {
23
- "copy": "copyfiles -f ../../LICENSE README.md package.json dist",
24
- "clean": "rimraf dist/**",
25
- "prepare": "npm run build",
26
- "build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy",
27
- "build:dev": "npm run clean; tsc --declarationMap; tsc -p tsconfig.esm.json; npm run copy",
28
- "lint": "eslint . --fix",
29
- "test": "jest",
30
- "test:watch": "jest --watch"
31
- },
32
- "dependencies": {
33
- "@launchql/logger": "^1.0.0",
34
- "@launchql/types": "^2.1.12",
35
- "lru-cache": "^11.1.0",
36
- "pg-env": "^1.0.0",
37
- "pg": "^8.16.0"
38
- },
39
- "devDependencies": {
40
- "@types/pg": "^8.15.2"
41
- },
42
- "keywords": [
43
- "postgresql",
44
- "pg",
45
- "pool",
46
- "cache",
47
- "lru",
48
- "connection",
49
- "launchql"
50
- ]
51
- }