Thanks to visit codestin.com
Credit goes to Github.com

Skip to content
/ hive Public

Embed SQLite in TypeScript with pluggable storage backends, automatic bidirectional sync, and runtime-agnostic support.

Notifications You must be signed in to change notification settings

ronin-co/hive

Repository files navigation

Hive

NPM Version Validate


Hive (hive) allows for seamlessly embedding SQLite-backed databases into modern TypeScript projects.

Its modular architecture and components allow it to scale from small in-memory demos or test scenarios to full-blown replicated and S3-based production setups.

Features:

  • Pure TypeScript and Web Standards
    Ships with components to support any runtime ranging from browsers and workers to full-fledged runtimes like Bun, Deno, or Node.

  • Pluggable Storage Backends
    Storage backends including MemoryStorage, DiskStorage, S3Storage, and RemoteStorage enable seamless implementation of Hive instances for testing, synchronized desktop and mobile clients, globally replicated APIs and more.

  • Built-in Replication & Sync
    Keep clients and server replicas in sync with automatic, bidirectional replication.

  • Extensible SDK
    Well-documented API for building custom components tailored to your specific needs.

  • Lightweight & Performant
    Optimized for tree-shaking to ship the most minimal bundle size. Hive is optimized both for scale and performance. Benchmarks follow.

Contents

Installation

In a project, simply add hive as a dependency using your package manager of choice (bun, pnpm, npm, ...):

bun add hive

Usage

import { Database, Hive } from 'hive';
import { MemoryStorage } from 'hive/memory-storage';
import { BunDriver } from 'hive/bun-driver';

// 1. Create a new Hive instance.
const hive = new Hive({
  driver: new BunDriver(),
  storage: new MemoryStorage(),
});

// 2. Create a new Database.
const db = await hive.create(new Database({ id: 'auth' }));

// 3. Query the Database.
interface User {
  id: string;
  handle: string;
}

await db.query([
  'CREATE TABLE users (id TEXT PRIMARY KEY, handle TEXT);',
  {
    sql: 'INSERT INTO users (id, handle) VALUES (?, ?);',
    params: [crypto.randomUUID(), 'juri'],
  },
]);

const [{ rows: users }] = await db.query<[User]>([
  'SELECT * FROM users;',
]);

// Recommended: Shut down gracefully.
process.on('SIGINT', async () => {
  await hive.stop();
  process.exit(0);
});

This concise example illustrates how to create a new Hive instance, create a new database, execute queries, and enable graceful shutdowns.

In future versions, drivers will be selected automatically, according to which one is best optimized for the current runtime.

Components

Hive

  • hive
    readme ⋅ examples
    Main entrypoint exporting the Hive class, which operates configured components.

Storage

Drivers

Resource Management

Networking

Customization and Development

About

Embed SQLite in TypeScript with pluggable storage backends, automatic bidirectional sync, and runtime-agnostic support.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •