https://github.com/pubkey/rxdb Skip to content Sign up * Why GitHub? Features - + Mobile - + Actions - + Codespaces - + Packages - + Security - + Code review - + Project management - + Integrations - + GitHub Sponsors - + Customer stories - + Security - * Team * Enterprise * Explore + Explore GitHub - Learn & contribute + Topics - + Collections - + Trending - + Learning Lab - + Open source guides - Connect with others + The ReadME Project - + Events - + Community forum - + GitHub Education - + GitHub Stars program - * Marketplace * Pricing Plans - + Compare plans - + Contact Sales - + Nonprofit - + Education - [ ] [search-key] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} pubkey / rxdb * Sponsor Sponsor pubkey/rxdb * Watch 230 * Star 15.1k * Fork 682 A realtime Database for JavaScript Applications rxdb.info/ Apache-2.0 License 15.1k stars 682 forks Star Watch * Code * Issues 3 * Pull requests 10 * Discussions * Actions * Security * Insights More * Code * Issues * Pull requests * Discussions * Actions * Security * Insights master 18 branches 63 tags Go to file Code Clone HTTPS GitHub CLI [https://github.com/p] Use Git or checkout with SVN using the web URL. [gh repo clone pubkey] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching Xcode If nothing happens, download Xcode and try again. Go back Launching Visual Studio If nothing happens, download the GitHub extension for Visual Studio and try again. Go back Latest commit @renovate-bot @renovate renovate-bot and renovate Update dependency karma to v6.1.0 ... 9babeaf Feb 3, 2021 Update dependency karma to v6.1.0 9babeaf Git stats * 4,941 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github ADD minor stuff Jan 24, 2021 config Use terser for better JS language feature support Jul 29, 2020 dist BUILD Jan 24, 2021 docs-src ADD(docs) #2805 warning about using keyCompression with remote non rx... Jan 23, 2021 docs BUILD Jan 24, 2021 examples Update dependency eslint to v7.19.0 Jan 31, 2021 orga ADD minor stuff Jan 24, 2021 plugins ADD sideEffects:false to all plugins Jun 20, 2020 scripts ADD link Jun 21, 2020 src UPGRADE typescript to 4.1.3 Jan 23, 2021 test Update dependency typescript to v4.1.3 Jan 24, 2021 .editorconfig Add editorconfig Oct 16, 2017 .eslintignore FIX lint Sep 9, 2018 .eslintrc.json ADD graphql-sync basic sync is working now Jul 8, 2019 .gitignore Merged `indexes` and `compoundIndexes` into a single field in the schema Nov 15, 2019 .npmignore fix: remove scripts dir from npmignore; will fix #1509 after npm publish Sep 25, 2019 .npmrc DISABLE package-lock.json Mar 19, 2018 CHANGELOG.md FIX link format Jan 24, 2021 ISSUE_TEMPLATE.md ADD check to prevent #2251 Jun 20, 2020 LICENSE.txt ADD LICENSE Dec 2, 2016 PULL_REQUEST_TEMPLATE.md ADD hint for #669 Jun 2, 2018 README.md Add minimum typescript version to readme Sep 2, 2020 babel.config.js CHORE typescript Sep 18, 2019 package.json Update dependency karma to v6.1.0 Feb 3, 2021 perf.md ADD RxDatabase.addCollections(), deprecate RxDatabase.colleciton() Nov 22, 2020 renovate.json Update renovate.json Nov 23, 2020 tsconfig.json ADD(server) pouchdbExpressOptions May 27, 2020 tslint.json FIX lint Jan 23, 2021 View code README.md Announcement Version 9.0.0 is now released, read the ANNOUNCEMENT [68747470733a2f2f63646e2e7261776769742e636f6d2f7075626] RxDB A realtime Database for JavaScript Applications RxDB (short for Reactive Database) is a NoSQL-database for JavaScript Applications like Websites, hybrid Apps, Electron-Apps, Progressive Web Apps and NodeJs. 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 way that makes it easy to develop and also has great performance benefits. To replicate data between your clients and server, RxDB provides modules for realtime replication with any CouchDB compliant endpoint and also with custom GraphQL endpoints. Documentation | Example-Projects [6874747073] follow on Twitter reactive.gif --------------------------------------------------------------------- Features Multiplatform support for browsers, nodejs, electron, cordova, react-native and every other javascript-runtime Reactive data-handling based on RxJS Offline first let your app still work when the users has no internet Replication between client and server-data, compatible with pouchdbPouchDB, couchdbCouchDB and cloudantIBM Cloudant. There is also a plugin for a GraphQL replication Schema-based with the easy-to-learn standard of json-schema Mango-Query exactly like you know from mongoDB and mongoose Encryption of single data-fields to protect your users data Import/Export of the database-state (json), awesome for coding with TDD Multi-Window to synchronise data between different browser-windows or nodejs-processes ORM-capabilities to easily handle data-code-relations and customize functions of documents and collections Full TypeScript support for fast and secure coding (Requires Typescript v3.8 or higher) Platform-support RxDB is made so that you can use exactly the same code at * Chrome Firefox Safari Edge Internet Explorer 11 Browsers * NodeJS NodeJS * electron Electron * react-native React-Native * cordova Cordova/Phonegap We optimized, double-checked and made boilerplates so you can directly start to use RxDB with frameworks like * angular Angular * vuejs Vuejs * react React * ionic Ionic2 Quickstart Installation: npm install rxdb --save # peerDependencies npm install rxjs --save Import: import { createRxDatabase } from 'rxdb'; const db = await createRxDatabase({ name: 'heroesdb', adapter: 'indexeddb', password: 'myLongAndStupidPassword' // optional }); // create database await db.collection({name: 'heroes', schema: mySchema}); // create collection db.heroes.insert({ name: 'Bob' }); // insert document Feature-Showroom (click to toggle) Mango-Query To find data in your collection, use the mquery api to create chained mango-queries, which you maybe know from mongoDB or mongoose. myCollection .find() .where('name').ne('Alice') .where('age').gt(18).lt(67) .limit(10) .sort('-age') .exec().then( docs => { console.dir(docs); }); Reactive RxDB implements rxjs to make your data reactive. This makes it easy to always show the real-time database-state in the dom without manually re-submitting your queries. db.heroes .find() .sort('name') .$ // <- returns observable of query .subscribe( docs => { myDomElement.innerHTML = docs .map(doc => '
  • ' + doc.name + '
  • ') .join(); }); reactive.gif MultiWindow/Tab When two instances of RxDB use the same storage-engine, their state and action-stream will be broadcasted. This means with two browser-windows the change of window #1 will automatically affect window #2. This works completely offline. multiwindow.gif Replication Because RxDB relies on glorious PouchDB, it is easy to replicate the data between devices and servers. And yes, the changeEvents are also synced. sync.gif Schema Schemas are defined via jsonschema and are used to describe your data. const mySchema = { title: "hero schema", version: 0, // <- incremental version-number description: "describes a simple hero", type: "object", properties: { name: { type: "string", primary: true // <- this means: unique, required, string and will be used as '_id' }, secret: { type: "string", }, skills: { type: "array", maxItems: 5, uniqueItems: true, item: { type: "object", properties: { name: { type: "string" }, damage: { type: "number" } } } } }, required: ["color"], encrypted: ["secret"] // <- this means that the value of this field is stored encrypted }; Encryption By setting a schema-field to encrypted, the value of this field will be stored in encryption-mode and can't be read without the password. Of course you can also encrypt nested objects. Example: { "title": "my schema", "properties": { "secret": { "type": "string", "encrypted": true } }, "encrypted": [ "secret" ] } Level-adapters The underlying pouchdb can use different adapters as storage engine. So you can use RxDB in different environments by just switching the adapter. For example you can use websql in the browser, localstorage in mobile-browsers and a leveldown-adapter in nodejs. // this requires the indexeddb-adapter RxDB.plugin(require('pouchdb-adapter-idb')); // this creates a database with the indexeddb-adapter const database = await RxDB.create({ name: 'mydatabase', adapter: 'indexeddb' // the name of your adapter }); There is a big ecosystem of adapters you can use. Import / Export RxDB lets you import and export the whole database or single collections into json-objects. This is helpful to trace bugs in your application or to move to a given state in your tests. // export a single collection const jsonCol = await myCollection.dump(); // export the whole database const jsonDB = await myDatabase.dump(); // import the dump to the collection await emptyCollection.importDump(json); // import the dump to the database await emptyDatabase.importDump(json); Leader-Election Imagine your website needs to get a piece of data from the server once every minute. To accomplish this task you create a websocket or pull-interval. If your user now opens the site in 5 tabs parallel, it will run the interval or create the socket 5 times. This is a waste of resources which can be solved by RxDB's LeaderElection. myRxDatabase.waitForLeadership() .then(() => { // this will only run when the instance becomes leader. mySocket = createWebSocket(); }); In this example the leader is marked with the crown reactive.gif Key-Compression Depending on which adapter and in which environment you use RxDB, client-side storage is limited in some way or the other. To save disc-space, RxDB uses a schema based keycompression to minimize the size of saved documents. This saves about 40% of used storage. Example: // when you save an object with big keys await myCollection.insert({ firstName: 'foo' lastName: 'bar' stupidLongKey: 5 }); // key compression will internally transform it to { '|a': 'foo' '|b': 'bar' '|c': 5 } // so instead of 46 chars, the compressed-version has only 28 // the compression works internally, so you can of course still access values via the original key.names and run normal queries. console.log(myDoc.firstName); // 'foo' EventReduce One big benefit of having a realtime database is that big performance optimizations can be done when the database knows a query is observed and the updated results are needed continuously. RxDB internally uses the Event-Reduce algorithm. This makes sure that when you update/ insert/remove documents, the query does not have to re-run over the whole database but the new results will be calculated from the events. This creates a huge performance-gain with zero cost. Use-Case-Example Imagine you have a very big collection with many user-documents. At your page you want to display a toplist with users which have the most points and are currently logged in. You create a query and subscribe to it. const query = usersCollection.find().where('loggedIn').eq(true).sort('points'); query.$.subscribe(users => { document.querySelector('body').innerHTML = users .reduce((prev, cur) => prev + cur.username+ '
    ', ''); }); As you may detect, the query can take very long time to run, because you have thousands of users in the collection. When a user now logs off, the whole query will re-run over the database which takes again very long. anyUser.loggedIn = false; await anyUser.save(); But not with the EventReduce. Now, when one user logs off, it will calculate the new results from the current results plus the RxChangeEvent. This often can be done in-memory without making IO-requests to the storage-engine. EventReduce not only works on subscribed queries, but also when you do multiple .exec()'s on the same query. Getting started Get started now by reading the docs or exploring the example-projects . Contribute Check out how you can contribute to this project. Follow up * Follow RxDB on twitter to not miss the latest enhancements. * Join the chat on gitter for discussion. Thank you A big Thank you to every contributor of this project. License Apache-2.0 About A realtime Database for JavaScript Applications rxdb.info/ Topics electron react nodejs couchdb graphql reactive rxjs react-native database pwa nosql json-schema pouchdb offline-first dapp realtime realtime-database rxdb Resources Readme License Apache-2.0 License Releases 63 9.12.1 Latest Jan 24, 2021 + 62 releases Sponsor this project Sponsor Learn more about GitHub Sponsors Packages 0 No packages published Used by 623 * @sooty2face * @HanzalahMd * @pwcandrew * @a1156883061 * @madipta * @Morpheuslabs-io * @joehannes * @JonathanTurnock + 615 Contributors 106 * @pubkey * @renovate-bot * @salomonelli * @rdworth * @ihadeed * @DDoerner * @rafamel * @lgandecki * @dome4 * @danielsun174 + 95 contributors Languages * TypeScript 98.5% * JavaScript 1.4% * Other 0.1% * (c) 2021 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.