Registry / database / ffc-database

ffc-database

JSON →
library1.0.24jsnpmunverified

ffc-database is an npm module developed by DEFRA, providing a structured utility layer for database interactions within FFC services. It is built upon the Sequelize ORM, abstracting common setup and model loading patterns. The module simplifies connecting to SQL databases (e.g., PostgreSQL, as shown in examples) by taking a configuration object, dynamically loading Sequelize models from a specified filesystem path, and exposing the connected Sequelize instance and loaded models. The current stable version is 1.0.24. While specific release cadence is not provided, its versioning and association with government services suggest a focus on stability and compatibility within its ecosystem. Its key differentiator lies in its opinionated, service-centric wrapper around Sequelize, streamlining database access for specific internal FFC applications.

database
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

The package primarily uses CommonJS `require()`. Direct ES module `import` syntax may not work without additional configuration or transpilation due to its CommonJS export structure.

const Base = require('ffc-database')

The `sequelize` instance is exposed directly on the object returned by `connect()`, allowing access to all native Sequelize methods like `authenticate()`, `close()`, and `query()`.

const dbBase = new Base(config); const db = dbBase.connect(); // Access sequelize instance: db.sequelize.authenticate();

Models are automatically loaded from `modelPath` and attached to the `db` object with their defined names (e.g., `Payment`). This pattern is part of the `ffc-database` abstraction.

const dbBase = new Base(config); const db = dbBase.connect(); // Access models by their defined name (e.g., 'Payment'): await db.Payment.findAll();

This quickstart demonstrates how to instantiate the `ffc-database` module, connect to a PostgreSQL database using environment variables for sensitive data, dynamically load Sequelize models, execute a simple raw SQL query, and gracefully close the database connection.

const Base = require('ffc-database'); const config = { dialect: 'postgres', host: process.env.DB_HOST ?? 'localhost', port: parseInt(process.env.DB_PORT ?? '5432', 10), database: process.env.DB_NAME ?? 'ffc_pay', username: process.env.DB_USER ?? 'ffc_user', password: process.env.DB_PASSWORD ?? 'ffc_password', modelPath: './models', // Assuming models directory exists in CWD ssl: process.env.DB_SSL === 'true' ?? false, logging: process.env.NODE_ENV !== 'production' }; // Minimal model file example (./models/payment.js): // module.exports = (sequelize, DataTypes) => { // const Payment = sequelize.define('Payment', { // amount: { type: DataTypes.DECIMAL }, // status: { type: DataTypes.STRING } // }); // Payment.associate = (models) => {}; // Define associations here // return Payment; // }; async function runDbOperations() { let dbBase; let db; try { dbBase = new Base(config); db = await dbBase.connect(); console.log('Database connected successfully.'); // Example: Run a raw query const [results, metadata] = await db.sequelize.query( 'SELECT 1 + 1 as solution;', { type: db.sequelize.QueryTypes.SELECT } ); console.log('Query result:', results); // Assuming a 'Payment' model exists and is defined in './models/payment.js' // const payments = await db.Payment.findAll(); // console.log('Found payments:', payments); } catch (error) { console.error('Database operation failed:', error); } finally { if (db && db.sequelize) { await db.sequelize.close(); console.log('Database connection closed.'); } } } runDbOperations();
Debug
Known footguns
gotchaThe module's examples and internal structure primarily use CommonJS (`require`). Integrating into a pure ES module (ESM) Node.js project may require specific `package.json` configurations (`'type': 'commonjs'`) or transpilation to avoid `SyntaxError: Named export 'X' not found` or `require() of ES modules is not supported` errors.
gotchaThe `modelPath` configuration expects a filesystem path to a directory containing JavaScript files that define Sequelize models. These files must adhere to the `module.exports = (sequelize, DataTypes) => { ... }` pattern. Incorrect paths or malformed model files will prevent models from being loaded.
gotchaThe `sequelize.close()` method should be called when your application is shutting down to release database connections. Once called, the `sequelize` instance cannot re-establish connections, requiring a new instance if further database operations are needed.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
16 hits · last 30 days
gptbot
4
ahrefsbot
4
amazonbot
4
bingbot
3
script
1
Resources