rxdb README

The project's README from github.com/pubkey/rxdb. As one markdown file: README.md.

JavaScript Database

A fast, local-first, reactive Database for JavaScript Applications


       

     


  What is RxDB?

RxDB (short for Reactive Database) is a local-first, NoSQL-database for JavaScript Applications. Reactive means that you can not only query the current state, but subscribe to all state changes like the result of a query or even a single field of a document. This is great for UI-based realtime applications in a way that makes it easy to develop and also has great performance benefits.

Use the quickstart, read the documentation or explore the example projects.

RxDB on Youtube

  Used by many

RxDB is a proven technology used by thousands of developers worldwide. With its flexibility, RxDB is used in a diverse range of apps and services.


(add yours)

  Multiplayer realtime applications

realtime.gif

  Replicate with your existing infrastructure

RxDB provides an easy to implement, battle-tested Sync Engine for realtime replication with your existing infrastructure.
You do not have to use a specific cloud or backend database. The protocol works by implementing three simple HTTP endpoints. There are also production-ready plugins to easily replicate with GraphQL, CouchDB, Websocket, WebRTC (P2P), Supabase, Firestore, NATS or Google Drive.

  Flexible storage layer

RxDB is based on a storage interface that enables you to swap out the underlying storage engine. This increases code reuse because the same database code can be used in different JavaScript environments by just switching out the storage settings.

You can use RxDB on top of LocalStorage, IndexedDB, OPFS, LokiJS, Dexie.js, in-memory, SQLite, in a WebWorker thread and even on top of FoundationDB and DenoKV.

No matter what kind of runtime you have, as long as it runs JavaScript, it can run RxDB:

Browsers Node.js React Native Capacitor NativeScript Flutter or as an Electron Database

All the features that you need

Since its beginning in 2018, RxDB has gained a huge set of features and plugins which makes it a flexible full solution regardless of which type of application you are building. Every feature that you need now or might need in the future is already there.

Logging
Attachments
ORM
Conflict Handling
Middleware
Signals
TanStack DB
State
Backup
Replication
Server
Storages
Local Documents
Schema Validation
Compression
Migration
Encryption
CRDT
Population

  Quick start

Install

npm install rxdb rxjs --save

Store data

import {
    createRxDatabase
} from 'rxdb/plugins/core';

/**
 * For browsers, we use the localstorage based storage.
 * In other JavaScript runtimes, we can use different storages:
 * @link https://rxdb.info/rx-storage.html
 */
import {
    getRxStorageLocalstorage
} from 'rxdb/plugins/storage-localstorage';

// create a database
const db = await createRxDatabase({
    name: 'heroesdb', // the name of the database
    storage: getRxStorageLocalstorage()
});

// add collections with a schema
await db.addCollections({
  heroes: {
    schema: {
      version: 0,
      primaryKey: 'name',
      type: 'object',
      properties: {
        name: {
          type: 'string',
          maxLength: 100
        },
        healthpoints: {
          type: 'number'
        }
      },
      required: ['name', 'healthpoints']
    }
  }
});

// insert a document
await db.heroes.insert({
  name: 'Bob',
  healthpoints: 100
});

Query data once

const aliveHeroes = await db.heroes.find({
  selector: {
    healthpoints: {
      $gt: 0
    }
  }
}).exec(); // the exec() returns the result once

Observe a Query

await db.heroes.find({
  selector: {
    healthpoints: {
      $gt: 0
    }
  }
})
.$ // the $ returns an observable that emits each time the result set of the query changes
.subscribe(aliveHeroes => console.dir(aliveHeroes));

  Get started

Get started now by reading the docs or exploring the example-projects.

  Support and Contribute

More content

Angular Database, Frontend Database, localStorage, React Database, Browser Database, React Native Database, PWA Database, In-memory NoSQL database, JSON database, Angular IndexedDB, React IndexedDB, Optimistic UI, local database, React Native Encryption, Vue Database, jQuery Database, Vue IndexedDB, Firestore Alternative, Firebase Realtime Database Alternative, Ionic Storage, Electron SQLite, TanStack DB Offline, DDIL Database


View llms.txt

rxdb (pubkey/rxdb)

Searching Database…

23.4K ·GitHub
这是什么?一个本地优先、响应式的 JavaScript 应用数据库:它直接运行在你的应用里,界面可以订阅查询结果,甚至订阅单个文档的字段,并且能与现有后端进行数据同步,不会被特定厂商绑定。
这是需要部署的数据库服务器,还是嵌入应用里的库?是一个库:RxDB 嵌入在你的 JavaScript 应用中,凡是能跑 JavaScript 的地方都能运行——浏览器、Node.js、Flutter 等等。不需要单独运维任何数据库进程。
怎么把它加到项目里开始使用?先用 npm 安装这个包,然后按照快速入门操作:创建集合、存储文档、执行一次性查询或订阅查询。其余内容可以参考文档和示例项目。
想让同步功能生效,我必须把后端搬到某个特定的云上吗?不用——同步只需要你自己实现三个简单的 HTTP 端点,而且针对 CouchDB、GraphQL、Firebase、Postgres 这类现有技术栈,都有可直接用于生产环境的插件。不要求使用特定的云。
全部功能都免费吗,还是有付费的部分?核心部分以 Apache-2.0 许可证开源,但有些功能是以付费插件的形式提供的,需要单独购买。
它经过了实战检验,还是仍处于实验阶段?经过了实战检验:项目从 2018 年就开始开发,全球有数千名开发者在各种应用和服务中使用 RxDB,实时多人协作应用是它的一个亮点使用场景。
设备离线时,我的应用会怎么样?照常运行——这正是本地优先模式:读写操作直接在本机数据库上即时完成,等网络恢复后,变更再与你的后端同步。
响应式在实际使用中是什么意思?查询结果甚至文档的单个字段都可以订阅:底层数据一有变化,界面就会自动收到更新。RxDB 表示这让实时界面的开发更简单、速度更快。
它能和哪些框架、环境集成?凡是能运行 JavaScript 的环境都行:浏览器、Node.js、Flutter、Electron 和 PWA,移动端通过 React Native 支持——README 里还专门列出了 Angular、React、Vue、Ionic 和 jQuery 的使用场景。
和 Firebase 或 Firestore 相比,为什么选它?README 把 RxDB 定位为 Firestore 和 Firebase Realtime Database 的替代方案:数据保存在本地,并与你现有的基础设施同步,所以不会被锁定在某个特定的云或厂商上。
Creator
pubkey
Size
637 MB
Stars
23.4K
Age
9y
Commits · 90 Days