Tuple Database is a local-first, embedded database designed for modern JavaScript and TypeScript applications, particularly those embracing the local-first software paradigm. It functions as a reactive, indexable graph database, often described as an 'embedded FoundationDb.' The library, currently at version 2.2.4, provides transactional read/write operations with a schemaless approach, where schemas are enforced by the application's type definitions rather than the database itself. It supports both synchronous and asynchronous storage backends, including SQLite or LevelDb, making it versatile for various environments. Key differentiators include its focus on freeing developers from the complexities of multi-tenant systems by empowering users with local data ownership, offering all reactive queries, and enabling direct manipulation of indexes for graph and relational queries. While the release cadence isn't explicitly stated, active development is indicated by its `2.x.x` versioning and comprehensive feature set, positioning it as a robust solution for frontend state management and embedded data persistence.
npm install tuple-databaseVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates defining a schema, initializing an in-memory database, performing transactional writes, and executing reactive scans. It also briefly mentions the React hook for state management.
Rigorously define and maintain your `Schema` TypeScript type. Use generic type parameters with `TupleDatabaseClient` and `transactionalReadWrite` to leverage TypeScript's type checking for all database operations.
Review the official changelog and migration guides for each major version upgrade. Update your tuple key definitions and API calls according to the new specifications.
Ensure the `TupleDatabaseClient` instance is explicitly passed as a prop to any React component that uses `useTupleDatabase`. For top-level components, this means providing it from your application's root.
Ensure your tuple keys strictly conform to the `Schema` type definitions, using object literals for named parts of the tuple key (e.g., `['user', {id: userId}]`).Use ES module `import` statements: `import { Symbol } from 'tuple-database';`. Configure your project's build system (Webpack, Rollup, Vite) or Node.js environment to handle ESM correctly.Always check if the result of a database operation is `null` or `undefined` before accessing its properties. Use optional chaining (`?.`) or type guards to ensure type safety, e.g., `if (result) { console.log(result.key); }`.