Database Integration
Working with PostgreSQL in the Node.js SDK.
Overview
The SDK provides a PostgreSQL client with:
- Connection pooling
- Health checks
- Automatic retries
- Query helpers
Configuration
TODO: Document database configuration
Environment Variables
DATABASE_URL=postgres://user:password@localhost:5432/myapp
DATABASE_POOL_SIZE=10
DATABASE_TIMEOUT=5000
Accessing the Database
The database client is available in AppContext:
const result = await context.db.query('SELECT * FROM users');
Query Methods
TODO: Document query methods:
query()- Execute SQL queryqueryOne()- Get single rowexecute()- Execute without results
Transactions
TODO: Document transaction support
await context.db.transaction(async (tx) => {
await tx.query('INSERT INTO ...');
await tx.query('UPDATE ...');
});
Migrations
TODO: Document migration strategy:
- Migration files
- Running migrations in onInstall hook
- Rollback support
Connection Pooling
TODO: Document connection pool configuration and management
Health Checks
TODO: Document database health checks
Best Practices
TODO: Document best practices:
- Use parameterized queries
- Handle connection errors
- Use transactions for multi-step operations
- Close connections on shutdown