{"library":"rxdb","title":"RxDB","description":"RxDB (Reactive Database) is a local-first, NoSQL database designed for JavaScript applications, including websites, hybrid apps, Electron, Progressive Web Apps, and Node.js. Currently stable at version 17.1.0, it follows a release cadence with frequent beta cycles leading to major versions and subsequent point releases for bug fixes. Its core differentiator is its reactive architecture, leveraging RxJS to provide observable queries and real-time data changes. RxDB supports offline-first operation, enforces data integrity through JSONSchema-based validation, and offers a highly pluggable synchronization engine for diverse backends like HTTP, GraphQL, WebRTC (P2P), CouchDB, MongoDB, Supabase, and even serverless options such as Google Drive and Microsoft OneDrive. Key features include conflict resolution (e.g., CRDTs), encryption, and robust data migration capabilities for evolving schemas and underlying storage adapters, ensuring data consistency across multiple client instances and browser tabs.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install rxdb"],"cli":null},"imports":["import { createRxDatabase } from 'rxdb';","import { addRxPlugin } from 'rxdb';","import { getRxStorageDexie } from 'rxdb/plugins/storage-dexie';","import type { RxJsonSchema } from 'rxdb';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { createRxDatabase, addRxPlugin } from 'rxdb';\nimport { getRxStorageDexie } from 'rxdb/plugins/storage-dexie';\nimport { RxDBDevModePlugin } from 'rxdb/plugins/dev-mode';\n\n// Add dev mode plugin in development for better error messages\nif (process.env.NODE_ENV !== 'production') {\n  addRxPlugin(RxDBDevModePlugin);\n}\n\nasync function runRxDBQuickstart() {\n  const mySchema = {\n    version: 0,\n    primaryKey: 'id',\n    type: 'object',\n    properties: {\n      id: { type: 'string', maxLength: 100 },\n      title: { type: 'string' },\n      done: { type: 'boolean', default: false }\n    },\n    required: ['id', 'title', 'done']\n  };\n\n  const db = await createRxDatabase({\n    name: 'mydatabase',\n    storage: getRxStorageDexie(),\n    multiInstance: true // Enable multi-tab synchronization\n  });\n\n  await db.addCollections({\n    todos: {\n      schema: mySchema\n    }\n  });\n\n  // Insert a document\n  await db.todos.insert({\n    id: 'todo-1',\n    title: 'Learn RxDB',\n    done: false\n  });\n\n  // Query documents\n  const allTodos = await db.todos.find().exec();\n  console.log('All todos:', allTodos.map(doc => doc.toJSON()));\n\n  // Subscribe to changes (reactive query)\n  const subscription = db.todos.find({\n    selector: { done: false }\n  }).$.subscribe(undoneTodos => {\n    console.log('Undone todos changed:', undoneTodos.map(doc => doc.toJSON()));\n  });\n\n  // Update a document\n  const todoToUpdate = await db.todos.findOne('todo-1').exec();\n  if (todoToUpdate) {\n    await todoToUpdate.patch({ done: true });\n  }\n\n  // Wait a moment for subscription to react and then clean up\n  setTimeout(async () => {\n    subscription.unsubscribe();\n    await db.destroy();\n    console.log('Database destroyed.');\n  }, 1000);\n}\n\nrunRxDBQuickstart();","lang":"typescript","description":"This quickstart demonstrates how to create an RxDB database, define a schema, add a collection, insert and query documents, and subscribe to real-time changes using the Dexie storage adapter. It also shows the conditional inclusion of the DevMode plugin for development.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}