Brackets Memory Database
brackets-memory-db is an in-memory implementation of the `CrudInterface` for the `brackets-manager.js` ecosystem, designed to store tournament bracket data directly in application memory. The current stable version is 1.0.5, last published over two years ago, indicating a stable but infrequent release cadence. It provides a simple, type-safe storage solution that is particularly well-suited for client-side applications running in the browser, where data persistence is managed by the client's session or explicitly handled by the application logic. It's also an excellent choice for testing, prototyping, or scenarios requiring temporary, ephemeral storage without the overhead of a persistent database. Its key differentiators are its tight integration with `brackets-manager.js` and its straightforward, zero-configuration setup for in-memory operations.
Common errors
-
Error: Cannot find module 'brackets-memory-db' or its corresponding type declarations.
cause This error often occurs when mixing CommonJS `require()` with an ESM-first package, using an incorrect import path, or when TypeScript cannot find the type definitions.fixEnsure you are using ESM `import { MemoryStorage } from 'brackets-memory-db';`. If in Node.js, ensure your `package.json` has `"type": "module"` or you are using `.mjs` files. For TypeScript, verify `tsconfig.json` settings (`moduleResolution`, `module`). -
TypeError: Cannot read properties of undefined (reading 'create')
cause This error typically indicates that the `BracketsManager` instance was not properly initialized with a valid storage implementation, or the storage instance itself is `undefined`.fixDouble-check that `const storage = new MemoryStorage();` successfully creates an instance and that `new BracketsManager(storage);` is correctly called, passing the `storage` object.
Warnings
- gotcha Data stored in `brackets-memory-db` is volatile and will be lost when the application process terminates or the browser page is refreshed. It does not provide any inherent persistence mechanism.
- gotcha This package is suitable for browser-based applications or backend processes where data can be re-generated or is explicitly saved externally. It is not designed as a primary, durable database for production systems requiring data integrity across restarts.
- gotcha The package's last publish was over two years ago. While this can indicate stability, it also means infrequent updates, which might lead to slower bug fixes or a delay in adopting new features or TypeScript versions from its `brackets-manager` peer dependency.
Install
-
npm install brackets-memory-db -
yarn add brackets-memory-db -
pnpm add brackets-memory-db
Imports
- MemoryStorage
const { MemoryStorage } = require('brackets-memory-db');import { MemoryStorage } from 'brackets-memory-db'; - MemoryStorage
import { MemoryStorage, CrudInterface } from 'brackets-memory-db';import type { CrudInterface } from 'brackets-manager';
Quickstart
import { BracketsManager } from 'brackets-manager';
import { MemoryStorage } from 'brackets-memory-db';
async function setupTournament() {
// 1. Instantiate the in-memory storage.
const storage = new MemoryStorage();
// 2. Pass the storage instance to the BracketsManager.
const manager = new BracketsManager(storage);
// 3. Create a new tournament.
await manager.create.tournament({
name: 'My Awesome Tournament',
slug: 'my-awesome-tournament',
description: 'A test tournament running in memory.',
sport: 'esports',
});
// 4. Create a stage for the tournament.
const tournamentId = (await manager.get.tournament('my-awesome-tournament'))?.id;
if (tournamentId === undefined) {
throw new Error('Tournament not found');
}
await manager.create.stage({
tournamentId,
name: 'Single Elimination Stage',
type: 'single_elimination',
seeding: ['Team A', 'Team B', 'Team C', 'Team D'],
settings: { size: 4 },
});
console.log('Tournament and stage created in memory!');
const matches = await manager.get.matches(tournamentId);
console.log('Current matches:', matches);
}
setupTournament().catch(console.error);