@devrev/meerkat-dbm

中文文档
0.1.49发布于 2026/10/15TypeScriptCommonJS构建来源已验证近 30 天下载 1.5万

@devrev/meerkat-dbm is a browser-first database management layer built on duckdb-wasm. It orchestrates query execution, manages DuckDB instances, caches files, persists data in browser storage, and optimizes memo

原始使用文档
文档目录10 节
  1. Architecture
  2. Why Meerkat DBM?
  3. Key Features
  4. 🚀 Database Management
  5. 📂 File Management
  6. Installation
  7. Usage
  8. 1. Implement the InstanceManager
  9. 2. Example: Sequential Queries with Persistent Storage
  10. 3. Example: Parallel Queries with IFrame Runners

@devrev/meerkat-dbm

@devrev/meerkat-dbm is a browser-first database management layer built on duckdb-wasm. It orchestrates query execution, manages DuckDB instances, caches files, persists data in browser storage, and optimizes memory usage to enable robust, high-performance data processing in web applications.

It's designed to bring the power of analytical SQL to the browser without compromising application stability or user experience. Whether you're building a data-intensive dashboard, an interactive reporting tool, or an offline-first application, Meerkat DBM provides the foundation you need.

Architecture

Meerkat DBM is composed of several key components that work together to manage data and execute queries in the browser:

  • DBM (Database Manager): The central orchestrator. It receives queries, manages the execution lifecycle, and coordinates with other components.
  • FileManager: Handles all aspects of data storage and retrieval. It can manage data in-memory or persist it to IndexedDB.
  • InstanceManager: A user-implemented component responsible for creating, managing, and terminating duckdb-wasm instances.
  • DuckDB Instances: The underlying duckdb-wasm engines where queries are executed, running in the main thread or in iFrames for parallelism.

This modular design provides a clear separation of concerns for managing complex data workflows in the browser.

Why Meerkat DBM?

While duckdb-wasm is incredibly powerful, using it directly in a complex web application can be challenging. Meerkat DBM provides a structured, production-ready layer that solves common problems:

  • 🧠 Memory Safety: Prevents Out-Of-Memory (OOM) errors by managing query queues and memory swapping, ensuring your app remains stable even with large datasets.
  • 💾 Persistence: Offers seamless IndexedDB storage, allowing data to persist across browser sessions.
  • 🗂️ Advanced File Management: Simplifies handling of various file formats (Parquet, JSON, remote URLs) with intelligent caching and partitioning.
  • ⚡ Parallel Processing: Unlocks high-performance analytics with an optional iframe-based architecture for parallel query execution, preventing UI freezes.

Key Features

🚀 Database Management

  • Instance Management: Automated lifecycle management for DuckDB instances.
  • Idle Recycle & Shutdown: Reclaim a worker's high-water memory after inactivity by recycling the engine (teardown + warm restart) before the final shutdown, with a consumer-supplied gate.
  • Connection Pooling: Efficient management of database connections.
  • Query Queueing: Intelligent scheduling of queries for sequential or parallel execution.
  • Table Locking: Ensures thread-safe table operations during concurrent access.

📂 File Management

  • Multiple Formats: Native support for Parquet, JSON files.
  • Bulk Operations: High-performance APIs for registering and processing files in bulk.
  • Partitioning: Support for table partitioning to efficiently manage and query large datasets.
  • Metadata Handling: Rich metadata support for tables and files.
  • Multiple Storage Modes: Flexible storage options, including in-memory and IndexedDB.

Installation

npm install @devrev/meerkat-dbm @duckdb/duckdb-wasm

Usage

1. Implement the InstanceManager

Meerkat DBM requires you to provide an InstanceManager. This decouples the library from a specific duckdb-wasm version, giving you full control over its instantiation and configuration.

// src/instance-manager.ts
import * as duckdb from '@duckdb/duckdb-wasm';
import { InstanceManagerType } from '@devrev/meerkat-dbm';

// Select the desired DuckDB bundle
const JSDELIVR_BUNDLES = duckdb.getJsDelivrBundles();

export class InstanceManager implements InstanceManagerType {
  private db: duckdb.AsyncDuckDB | null = null;

  private async initDB(): Promise<duckdb.AsyncDuckDB> {
    const bundle = await duckdb.selectBundle(JSDELIVR_BUNDLES);

    const worker_url = URL.createObjectURL(new Blob([`importScripts("${bundle.mainWorker!}");`], { type: 'text/javascript' }));

    const worker = new Worker(worker_url);
    const logger = { log: (msg: any) => console.log(msg) };
    const db = new duckdb.AsyncDuckDB(logger, worker);

    await db.instantiate(bundle.mainModule, bundle.pthreadWorker);

    URL.revokeObjectURL(worker_url);
    return db;
  }

  async getDB(): Promise<duckdb.AsyncDuckDB> {
    if (!this.db) {
      this.db = await this.initDB();
    }
    return this.db;
  }

  async terminateDB(): Promise<void> {
    if (this.db) {
      await this.db.terminate();
      this.db = null;
    }
  }
}

2. Example: Sequential Queries with Persistent Storage

This example uses the DBM with an IndexedDBFileManager for safe, sequential query execution and data persistence across browser sessions.

import { DBM, IndexedDBFileManager } from '@devrev/meerkat-dbm';
import { InstanceManager } from './instance-manager';

// 1. Create the managers
const instanceManager = new InstanceManager();
const fileManager = new IndexedDBFileManager({
  instanceManager,
  // This function is called by Meerkat to fetch file data when needed
  fetchTableFileBuffers: async (tableName) => {
    // In a real app, you would fetch data from a indexdb
    return [];
  },
});

// 2. Create the DBM instance
const dbm = new DBM({
  instanceManager,
  fileManager,
  onEvent: (event) => console.info('DBM Event:', event),
  options: {
    // Optional intermediate "recycle" after 2s of inactivity: tear down the
    // DuckDB instance and immediately re-instantiate it. Reclaims the worker's
    // high-water memory (WASM linear memory only grows) while keeping the
    // engine warm for the next query. Must be less than shutdownInactiveTime.
    recycleInactiveTime: 2000,
    // Optional gate consulted before each recycle. Return false to skip it
    // (e.g. nothing worth reclaiming). Defaults to always-recycle when omitted.
    shouldRecycle: () => true,
    // Automatically shut down the DuckDB instance after 5s of inactivity
    shutdownInactiveTime: 5000,
  },
});

// 3. Register data
await fileManager.registerJSON({
  tableName: 'sales',
  fileName: 'sales.json',
  json: [
    { id: 1, product: 'Laptop', amount: 1200 },
    { id: 2, product: 'Mouse', amount: 25 },
    { id: 3, product: 'Keyboard', amount: 75 },
  ],
});

// 4. Run a query
const results = await dbm.query('SELECT * FROM sales WHERE amount > 50');
console.log(results);

3. Example: Parallel Queries with IFrame Runners

This setup uses DBMParallel and ParallelIndexedDBFileManager for maximum performance, executing queries in parallel across multiple iframe-based DuckDB instances.

import { DBMParallel, IFrameRunnerManager, ParallelIndexedDBFileManager } from '@devrev/meerkat-dbm';
import log from 'loglevel';
import { InstanceManager } from './instance-manager';

// 1. Create instance and file managers
const instanceManager = new InstanceManager();
const fileManager = new ParallelIndexedDBFileManager({
  instanceManager,
  fetchTableFileBuffers: async (table) => [],
  logger: log,
});

// 2. Set up the iframe runner manager for parallel execution
const iframeManager = new IFrameRunnerManager({
  // URL to the runner HTML file that hosts the DuckDB instance
  runnerURL: 'http://localhost:4204/runner/indexeddb-runner.html',
  origin: 'http://localhost:4204',
  totalRunners: 4, // Number of parallel iframes
  fetchTableFileBuffers: async (table) => [],
  logger: log,
});

// 3. Create the parallel DBM instance
const parallelDBM = new DBMParallel({
  instanceManager,
  fileManager,
  iFrameRunnerManager: iframeManager,
  logger: log,
  options: {
    shutdownInactiveTime: 10000,
  },
});

// 4. Register data
await fileManager.bulkRegisterJSON([
  {
    tableName: 'transactions',
    fileName: 'transactions.json',
    json: [
      { id: 1, product_id: 101, amount: 1200 },
      { id: 2, product_id: 102, amount: 25 },
    ],
  },
  {
    tableName: 'products',
    fileName: 'products.json',
    json: [
      { id: 101, name: 'Laptop', category: 'Electronics' },
      { id: 102, name: 'Mouse', category: 'Accessories' },
    ],
  },
]);

// 5. Execute queries in parallel
const results = await Promise.all([
  parallelDBM.query('SELECT * FROM transactions WHERE amount > 100'),
  parallelDBM.query(`
    SELECT p.category, COUNT(*) as product_count 
    FROM transactions t 
    JOIN products p ON t.product_id = p.id 
    GROUP BY p.category
  `),
]);

console.log('Query Results', results);

版本与发布记录

@devrev/meerkat-dbm 共发布 28 个版本,首次发布于 2024/09/05;过去 12 个月发布了 13 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.49latest2026/10/1527 天前
0.1.482026/10/081 个月前
0.1.472026/07/024 个月前
0.1.462026/07/024 个月前
0.1.452026/07/014 个月前
0.1.442026/06/254 个月前

关于 @devrev/meerkat-dbm 的常见问题

@devrev/meerkat-dbm 是什么?

@devrev/meerkat-dbm is a browser-first database management layer built on duckdb-wasm. It orchestrates query execution, manages DuckDB instances, caches files, persists data in browser storage, and optimizes memo

如何安装 @devrev/meerkat-dbm?

在项目目录运行 npm install @devrev/meerkat-dbm,或使用 pnpm add / yarn add / bun add。

@devrev/meerkat-dbm 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@devrev/meerkat-dbm 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@devrev/meerkat-dbm 可以商用吗?

@devrev/meerkat-dbm 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@devrev/meerkat-dbm 的下载量有多少?

根据 npm 官方下载统计,@devrev/meerkat-dbm 在 2026/10/12 – 2026/11/10 这 30 天内被下载 14,778 次,日均约 493 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@devrev/meerkat-dbm 还在维护吗?

最新版本 0.1.49 发布于 2026/10/15(27 天前);至今共发布 28 个版本,其中过去 12 个月发布了 13 个;首次发布于 2024/09/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。