Skip to main content

Creating Plugins

Creating your own plugin is very simple. A plugin is basically a javascript-object which overwrites or extends RxDB's internal classes, prototypes, and hooks.

A basic plugin:


const myPlugin = {
rxdb: true, // this must be true so rxdb knows that this is a rxdb-plugin
/**
* (optional) init() method
* that is called when the plugin is added to RxDB for the first time.
*/
init() {
// import other plugins or initialize stuff
},
/**
* every value in this object can manipulate the prototype of the keynames class
* You can manipulate every prototype in this list:
* @link https://github.com/pubkey/rxdb/blob/master/src/plugin.ts#L22
*/
prototypes: {
/**
* add a function to RxCollection so you can call 'myCollection.hello()'
*
* @param {object} prototype of RxCollection
*/
RxCollection: (proto) => {
proto.hello = function() {
return 'world';
};
}
},
/**
* some methods are static and can be overwritten in the overwritable-object
*/
overwritable: {
validatePassword: function(password) {
if (password && typeof password !== 'string' || password.length < 10)
throw new TypeError('password is not valid');
}
},
/**
* you can add hooks to the hook-list
*/
hooks: {
/**
* add a `foo` property to each document. You can then call myDocument.foo (='bar')
*/
createRxDocument: {
/**
* You can either add the hook running 'before' or 'after'
* the hooks of other plugins.
*/
after: function(doc) {
doc.foo = 'bar';
}
}
}
};

// now you can import the plugin into rxdb
addRxPlugin(myPlugin);

Properties

rxdb​

The rxdb-property signals that this plugin is an rxdb-plugin. The value should always be true.

prototypes​

The prototypes-property contains a function for each of RxDB's internal prototype that you want to manipulate. Each function gets the prototype-object of the corresponding class as parameter and then can modify it. You can see a list of all available prototypes here

overwritable​

Some of RxDB's functions are not inside of a class-prototype but are static. You can set and overwrite them with the overwritable-object. You can see a list of all overwritables here.

hooks

Sometimes you don't want to overwrite an existing RxDB-method, but extend it. You can do this by adding hooks which will be called each time the code jumps into the hooks corresponding call. You can find a list of all hooks here.

options

RxDatabase and RxCollection have an additional options-parameter, which can be filled with any data required be the plugin.

const collection = myDatabase.addCollections({
foo: {
schema: mySchema,
options: { // anything can be passed into the options
foo: ()=>'bar'
}
}
})

// Afterwards you can use these options in your plugin.

collection.options.foo(); // 'bar'

RxDB: The Fastest and Most Reliable Local Database

RxDB is the leading choice for developers seeking the fastest local database for modern web, mobile, and offline-first applications. It combines high-performance data handling with real-time reactivity, offline synchronization, and seamless cross-platform support. Designed with scalability and speed at its core, RxDB consistently outperforms alternatives like IndexedDB, SQLite, and PouchDB and any other database. It is the easiest to set up and learn. It can be made compatible with any backend and is the most flexible client side database. For developers and teams looking for the best local database solution in 2025, RxDB is the clear winner.

✕