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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
AutoConfig
✓ import { AutoConfig } from 'futoin-database';
✗ const AutoConfig = require('futoin-database').AutoConfig;
While CommonJS `require` is supported by Node.js `>=6`, modern TypeScript/ESM projects should use named `import`.
QueryBuilder
✓ import { QueryBuilder } from 'futoin-database';
✗ import QueryBuilder from 'futoin-database';
QueryBuilder is a named export, not a default export. Ensure curly braces for named import syntax.
IDataBaseService
✓ import { IDataBaseService } from 'futoin-database';
✗ const IDataBaseService = require('futoin-database');
This symbol represents the database interface definition, primarily useful for TypeScript type checking. Runtime interaction is typically through an instance obtained from a Container Connection Manager (CCM).
Demonstrates auto-configuration of an in-memory SQLite database, executing a basic query (Level 1), and a multi-statement transaction with an implicit rollback on failure (Level 2). It showcases the FutoIn database interface's core usage patterns, including integration with `futoin-asyncsteps` and `futoin-executor`.
/*
Installation:
npm install futoin-asyncsteps futoin-executor futoin-invoker futoin-database sqlite3
(sqlite3 is an optional peer dependency for SQLite support that must be explicitly installed if you use it.)
*/
// Set environment variables for a test in-memory SQLite database.
// In a real application, these would be set externally (e.g., .env file, Docker config).
process.env.DB_TYPE = 'sqlite';
process.env.DB_PATH = ':memory:'; // Use an in-memory SQLite DB for quick demonstration
process.env.DB_MAXCONN = '1';
process.env.FUTOIN_DB_ALIAS = 'my_sqlite_db'; // Custom alias for clarity
const AsyncSteps = require('futoin-asyncsteps');
const Executor = require('futoin-executor'); // Required for ContainerConnectionManager
const { AutoConfig } = require('futoin-database');
// Create a FutoIn Container Connection Manager (CCM)
const ccm = new Executor.ContainerConnectionManager();
// Main execution block using AsyncSteps for flow control
AsyncSteps((as) => {
// 1. Auto-configure the database connection using environment variables.
// The configuration object indicates supported types, and the last argument
// is the alias under which the DB service will be registered in CCM.
AutoConfig(as, ccm, {
[process.env.FUTOIN_DB_ALIAS]: { type: ['sqlite'] }
}, process.env.FUTOIN_DB_ALIAS);
as.add((as) => {
console.log(`Database service '${process.env.FUTOIN_DB_ALIAS}' configured.`);
// 2. Get the database service instance from the CCM
const db = ccm.get(process.env.FUTOIN_DB_ALIAS);
// 3. Execute a simple query (Level 1 interface)
console.log('\n--- Executing simple query (Level 1) ---');
db.query(as, 'SELECT ? + ? AS result_value', [10, 20]);
as.add((as, rows) => {
console.log('Query result:', rows);
console.log('10 + 20 =', rows[0].result_value);
// 4. Execute a multi-statement transaction (Level 2 interface)
// This transaction creates a table, inserts data, and then selects it.
// If any step fails, the entire transaction is rolled back.
console.log('\n--- Executing transaction (Level 2) ---');
const tx = [
// Statement 0: Create table if not exists
'CREATE TABLE IF NOT EXISTS sample_users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, email TEXT)',
// Statement 1: Insert data for User A
{ query: 'INSERT INTO sample_users (name, email) VALUES (?, ?)', params: ['Charlie', 'charlie@example.com'] },
// Statement 2: Insert data for User B
{ query: 'INSERT INTO sample_users (name, email) VALUES (?, ?)', params: ['Diana', 'diana@example.com'] },
// Statement 3: Select data for User A by name
{ query: 'SELECT id, name, email FROM sample_users WHERE name = ?', params: ['Charlie'], expect: 'rows' },
// Statement 4: Select data for User B by email
{ query: 'SELECT id, name, email FROM sample_users WHERE email = ?', params: ['diana@example.com'], expect: 'rows' }
];
db.transaction(as, tx);
as.add((as, results) => {
console.log('Transaction results:');
// 'results' is an array where each element corresponds to the outcome of a statement in 'tx'.
// For 'expect: rows', it will contain an array of row objects.
console.log('Charlie data:', results[3][0]); // Result of statement 3
console.log('Diana data:', results[4][0]); // Result of statement 4
if (results[3][0].name === 'Charlie' && results[4][0].name === 'Diana') {
console.log('Transaction successful: data inserted and retrieved correctly.');
}
});
});
});
},(as, err) => {
console.error('An error occurred during execution:', err.message);
// Ensure connections are released on error
ccm.release();
process.exit(1);
}).whenEnd(() => {
console.log('\nQuickstart execution complete. Releasing resources.');
// Ensure connections are released upon successful completion
ccm.release();
process.exit(0);
});
Errors
Common errors & fixes
Error: Cannot find module 'futoin-asyncsteps' (or futoin-executor, futoin-invoker)
One of the required FutoIn peer dependencies is missing from your project's `node_modules`.
fixInstall the missing peer dependencies: `npm install futoin-asyncsteps futoin-executor futoin-invoker`.
Error: Service 'your_db_alias' is not registered in CCM
The `AutoConfig` function was either not called, failed to execute, or the alias provided to `ccm.get()` does not match the one used during configuration.
fixVerify that `AutoConfig(as, ccm, config, alias)` is called successfully before `ccm.get(alias)`. Double-check the alias string for consistency and ensure environment variables (like `DB_TYPE`, `DB_PATH`) are correctly set if using auto-configuration.
TypeError: db.query is not a function
The object retrieved from `ccm.get()` is not a valid FutoIn database service instance, or the underlying database driver failed to initialize, resulting in an incomplete service object.
fixEnsure `AutoConfig` successfully initializes the database connection and registers the service. Check the console for earlier errors during `AutoConfig` execution. Confirm that the required database driver (e.g., `sqlite3` for SQLite) is correctly installed and accessible by `futoin-database`.
Audit
Dependencies
futoin-asyncstepsrequiredCore library for asynchronous control flow, fundamental to FutoIn ecosystem operation.
futoin-executorrequiredProvides the ContainerConnectionManager (CCM) for managing services and connections.
futoin-invokerrequiredPart of the FutoIn invocation mechanism, often used with Executor and CCM.