网页
综合
更新时间 2026-11-05 12:53:57
Quickstart | RxDB
自动蜘蛛
rxdb.info
正文约 2356 字
Welcome to the RxDB Quickstart. Here we'll learn how to create a simple real-time app with the RxDB database that is able to store and query data persistently in a browser and does realtime updates to the UI on changes.
Install the RxDB library and the RxJS dependency:
RxDB is able to run in a wide range of JavaScript runtimes like browsers, mobile apps, desktop and servers. Therefore different storage engines exist that ensure the best performance depending on where RxDB is used.
Use this for the simplest browser setup and very small datasets. It has a tiny bundle size and works anywhere localStorage is available, but is not optimized for large data or heavy writes.
RxDB provides a wide range of storages depending on your JavaScript runtime and performance needs.
When you use RxDB in development, you should always enable the dev-mode plugin, which adds helpful checks and validations, and tells you if you do something wrong.
Schema validation is required when using dev-mode and recommended (but optional) in production. Wrap your storage with the AJV schema validator to ensure all documents match your schema before being saved.
A database is the top‑level container in RxDB, responsible for managing collections, coordinating persistence, and providing reactive change streams.
An RxDatabase contains RxCollections for storing and querying data. A collection is similar to an SQL table, and individual records are stored in the collection as JSON documents. An RxDatabase can have as many collections as you need. Add a collection with a schema to the database:
Now that we have an RxCollection we can store some documents in it.
Execute a query that returns all found documents once:
In the first found document, set done to true:
Delete the document so that it can no longer be found in queries:
Subscribe to data changes so that your UI is always up-to-date with the data stored on disk. RxDB allows you to subscribe to data changes even when the change happens in another part of your application, another browser tab, or during database replication/synchronization:
You can also subscribe to the fields of a single RxDocument. Add the $ sign to the desired field and then subscribe to the returned observable.
RxDB has multiple replication plugins to replicate database state with a server.
You are now ready to dive deeper into RxDB.
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。