Neon PostgreSQL integration reference — 3 backend files. Connection pooling, parameterized queries, and data migration scripts alongside Firestore
A3 uses Neon PostgreSQL alongside Firestore for use cases that require relational queries, vector similarity search, complex aggregations, and structured data exports. This skill covers the 3 backend files, connection pooling, parameterized queries, SQL injection prevention, the Neon serverless driver, data migration scripts, and guidance on when to use Postgres vs Firestore.
| File | Purpose |
|---|---|
functions/src/utils/db.ts | PostgreSQL pool setup, connection management, query helpers |
functions/src/neon/client-upload.ts | Script to bulk upload client data from Firestore to Neon |
functions/src/neon/client-remove.ts | Script to remove client data from Neon when deleted in Firestore |
A3 maintains Firestore as the primary database for real-time data and Neon PostgreSQL as a secondary store for:
utils/db.tspg// functions/src/utils/db.ts
import { Pool, PoolConfig, QueryResult } from 'pg';
const poolConfig: PoolConfig = {
connectionString: process.env.NEON_DATABASE_URL!,
ssl: {
rejectUnauthorized: true,
},
max: 10, // Maximum pool connections
idleTimeoutMillis: 30000, // Close idle connections after 30s
connectionTimeoutMillis: 10000, // Timeout connecting after 10s
allowExitOnIdle: true, // Allow process to exit if pool is idle
};
export const pool = new Pool(poolConfig);
// Log pool errors
pool.on('error', (err) => {
console.error('Unexpected Neon pool error:', err);
});
// Graceful shutdown
process.on('SIGTERM', async () => {
await pool.end();
});