Extending Kinto.js

Custom database adapters

By default, Kinto.js performs all local persistence operations using IndexedDB; though if you want to create and use you own, that's definitely possible.

Simply create a class extending from Kinto.adapters.BaseAdapter, which acts as an abstract class:

class MyAdapter extends Kinto.adapters.BaseAdapter {
  constructor(dbname) {
    super();
    this.dbname = dbname;
  }

  open() {
    // open a database connection
    return super.open();
  }

  close() {
    // close a database connection
    return super.close();
  }

  create(record) {
    // add a record to the database
  }

  update(record) {
    // update a record from the database
  }

  …
}

Note that #open() and #close() are implemented and are simply resolving by default.

Then create the Kinto object passing a reference to your adapter class:

const kinto = new Kinto({adapter: MyAdapter});

Read the BaseAdapter class source code to figure out what needs to be implemented exactly. IDB and LocalStorage adapters are also worth a read if you need guidance writing your own.