UNPKG

@variablesoftware/mock-d1

Version:

🎛️🗂️🧠 Mock D1 Database implementation for testing Cloudflare Workers

26 lines (25 loc) 1.13 kB
import { injectTableRows } from './injectTableRows.js'; import { log } from '@variablesoftware/logface'; /** * Injects rows into a table in the mock D1 database (mock only). * Emits a warning if used outside of test environments. * @param db - The internal Map of tables to rows. * @param tableName - The table name. * @param columns - The explicit table schema columns (required). * @param rows - The rows to inject. */ export function mockInject(db, tableName, columns, rows) { if (typeof process !== 'undefined' && process.env.NODE_ENV !== 'test') { log.warn('mockInject() is a mock/test-only API and should not be used in production.'); } // Debug output for test troubleshooting if (process.env.DEBUG || process.env.MOCK_D1_DEBUG) { log.debug('called with:', { tableName, columns, rows }); log.debug('db keys before:', Array.from(db.keys())); } injectTableRows(db, tableName, columns, rows); if (process.env.DEBUG || process.env.MOCK_D1_DEBUG) { log.debug('db keys after:', Array.from(db.keys())); log.debug('table after:', db.get(tableName)); } }