Registry / database / anatomic-postgres

anatomic-postgres

JSON →
library0.4.0jsnpmunverified

Anatomic-postgres is a lifecycle component for integrating the Postgres.js SQL client into the Anatomic dependency injection system for Node.js. At version 0.4.0, it wraps the 'postgres' module (commonly known as 'postgres.js') to provide managed connection lifecycle (start/stop) and configuration injection. Unlike direct use of postgres.js, this package enables declarative setup, automatic connection pooling, and graceful shutdown within an Anatomic system. It is designed for projects already using Anatomic and seeking to attach a PostgreSQL client as a managed dependency. The package is actively maintained.

npm install anatomic-postgres
INSTALL
IMPORT
SIG · ANATOMIC-POSTGRES
A
anatomic-postgres
databasejavascriptv0.4.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.

default
const pg = require('anatomic-postgres');
import pg from 'anatomic-postgres';
The package does not ship ESM; requires CommonJS require. Named export is not available.
pg (factory)
const pg = require('anatomic-postgres');
In CommonJS, the default export is a factory function that returns an Anatomic component.
component factory
const pgComponent = require('anatomic-postgres').default;
const { default } = require('anatomic-postgres');
TypeScript users may need to access .default due to esModuleInterop.

Shows how to set up an Anatomic system with a PostgreSQL client, configure connection string, start/stop, and run a query.

const anatomic = require('anatomic'); const pg = require('anatomic-postgres'); async function main() { const system = anatomic() .add('postgres', pg()) .dependsOn('config') .configure({ postgres: { connectionString: process.env.DATABASE_URL ?? 'postgres://localhost:5432/mydb' } }); const { postgres } = await system.start(); const result = await postgres.query`SELECT version();`; console.log(result); await system.stop(); } main().catch(console.error);
Debug
Known issues
gotchaThe component factory expects a 'config' dependency to be present; if not added, the system will fail on start.
fix
Ensure that 'config' is added to the Anatomic system before 'postgres' (e.g., .add('config', {postgres: {...}}).dependsOn('config') is already done but the config object must be provided.)
affects: >=0.0.0
gotchaThe package does not support ESM imports; require() is required.
fix
Use CommonJS require() or set up a bundler with appropriate transformation.
affects: >=0.0.0
deprecatedVersion 0.x may change API drastically. Check changelog before upgrading.
fix
Pin exact version and review release notes.
affects: >=0.0.0 <1.0.0
Errors
Common errors & fixes
TypeError: pg is not a function
Importing the module incorrectly (e.g., as default in CJS) without calling require or using destructuring.
fix
const pg = require('anatomic-postgres'); // call the factory pg()
Error: Missing dependencies: config
The 'postgres' component has a dependency on 'config' but no 'config' component was added to the system.
fix
Add a 'config' component to the system, e.g., .add('config', {})
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies
anatomicoptionalruntime peer dependency; this package integrates with Anatomic's DI system
postgresoptionalruntime peer dependency; the underlying PostgreSQL client library
Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
anatomic-postgres — npm install anatomic-postgres · libregistry