How to use rxdb - 10 common examples

To help you get started, we’ve selected a few rxdb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pubkey / rxdb / test / tutorials / src / typescript.ts View on Github external
/**
 * this is the test for the typescript-tutorial
 * IMPORTANT: whenever you change something here,
 * ensure it is also changed in /docs-src/tutorials/typescript.md
 */

// import types
import RxDB, {
    RxDatabase,
    RxCollection,
    RxJsonSchema,
    RxDocument
} from 'rxdb';

import * as MemoryAdapter from 'pouchdb-adapter-memory';
RxDB.plugin(MemoryAdapter);

/**
 * declare types
 */

type HeroDocType = {
    passportId: string;
    firstName: string;
    lastName: string;
    age?: number; // optional
};

type HeroDocMethods = {
    scream: (v: string) => string;
};
github pubkey / rxdb / test / tutorials / src / server.ts View on Github external
async function run() {


    // create database
    const db = await RxDB.create({
        name: 'mydb',
        adapter: 'memory'
    });

    // create a collection
    const mySchema = {
        version: 0,
        type: 'object',
        properties: {
            key: {
                type: 'string',
                primary: true
            },
            value: {
                type: 'string'
            }
github salomonelli / nirania / src / services / database.service.js View on Github external
import * as RxDB from 'rxdb';
RxDB.plugin(require('pouchdb-adapter-idb'));
RxDB.plugin(require('pouchdb-replication')); //enable syncing
RxDB.plugin(require('pouchdb-adapter-http')); //enable syncing over http

const syncURL = 'http://' + window.location.hostname + ':10102/';
console.log('host: ' + syncURL);
// const syncURL = host;

let dbPromise = null;

const _create = async function() {
    console.log('DatabaseService: creating database..');
    const db = await RxDB.create({
        name: 'niraniadb',
        adapter: 'idb',
        password: 'myLongAndStupidPassword'
    });
github decentralized-identity / element / packages / element-lib / src / adapters / database / ElementRXDBAdapter.js View on Github external
async _init() {
    // Only create db if it doesnt exist already
    this.db = await RxDB.create({
      name: this.name,
      adapter: this.adapter,
      multiInstance: false,
    });
    this.collection = await this._createCollection();
  }
github eh3rrera / react-rxdb-example / src / App.js View on Github external
async createDatabase() {
    // password must have at least 8 characters
    const db = await RxDB.create(
      {name: dbName, adapter: 'idb', password: '12345678'}
    );
      console.dir(db);

    // show who's the leader in page's title
    db.waitForLeadership().then(() => {
      document.title = '♛ ' + document.title;
    });

    // create collection
    const messagesCollection = await db.collection({
      name: 'messages',
      schema: schema
    });

    // set up replication
github pubkey / rxdb / examples / vue / src / services / Database.service.ts View on Github external
async function _create(): Promise {
    console.log('DatabaseService: creating database..');
    const db = await RxDB.create({
        name: 'heroes',
        adapter: useAdapter,
        queryChangeDetection: true
        // password: 'myLongAndStupidPassword' // no password needed
    });
    console.log('DatabaseService: created database');
    (window as any).db = db; // write to window for debugging

    // show leadership in title
    db.waitForLeadership()
        .then(() => {
            console.log('isLeader now');
            document.title = '♛ ' + document.title;
        });

    // create collections
github johannesjo / super-productivity / src / app / core / rxdb / ngx-rxdb.service.ts View on Github external
async initDb(config: NgxRxdbConfig) {
    console.log('INIT DB');
    try {
      const db: RxDatabase = await RxDB.create({
        ...DEFAULT_CONFIG,
        ...config
      });
      this._dbInstance = db;
      console.log(this.db);
      console.log('RxdbService: created database');
      // also can create collections from root config
      if (config && config.options && config.options.schemas) {
        await this.initCollections(config.options.schemas);
        console.log('RxdbService: created collections bulk');
      }
      console.log(config);

      if (config && config.options && config.options.dumpPath) {
        // fetch dump json
        const dump = await (await fetch(config.options.dumpPath)).json();
github pubkey / rxdb / examples / angular2 / app / src / services / database.service.ts View on Github external
async function _create(): Promise {
    console.log('DatabaseService: creating database..');
    const db = await RxDB.create({
        name: 'heroes',
        adapter: useAdapter,
        queryChangeDetection: true
        // password: 'myLongAndStupidPassword' // no password needed
    });
    console.log('DatabaseService: created database');
    (window as any)['db'] = db; // write to window for debugging

    // show leadership in title
    db.waitForLeadership()
        .then(() => {
            console.log('isLeader now');
            document.title = '♛ ' + document.title;
        });

    // create collections
github pubkey / rxdb / examples / angular / src / app / services / database.service.ts View on Github external
async function _create(): Promise {

    await loadRxDBPlugins();

    console.log('DatabaseService: creating database..');
    const db = await RxDB.create({
        name: 'angularheroes',
        adapter: 'idb',
        queryChangeDetection: true
        // password: 'myLongAndStupidPassword' // no password needed
    });
    console.log('DatabaseService: created database');
    (window as any)['db'] = db; // write to window for debugging

    // show leadership in title
    db.waitForLeadership()
        .then(() => {
            console.log('isLeader now');
            document.title = '♛ ' + document.title;
        });

    // create collections
github johannesjo / super-productivity / src / app / core / rxdb / ngx-rxdb.service.ts View on Github external
async createCollection(schemaConfig: NgxRxdbCollectionConfig) {
    console.log('CREATE COLLECTION');

    // TODO this needs to be fixed to be available initially
    await promiseTimeout(2500);

    if (!schemaConfig || !schemaConfig.schema) {
      throw new Error('RxdbService: missing schema object');
    }
    let collection: RxCollection = this.db[name];
    // delete collection if exists
    if (RxDB.isRxCollection(collection)) {
      console.log('RxdbService: collection', name, 'exists, skip create');
      await collection.remove();
    }
    collection = await this.db.collection(new NgxRxdbCollectionCreator(schemaConfig));
    console.log(`RxdbService: created collection "${name}"`);
    // preload data into collection
    const docsCount = await collection.countAllDocuments();
    console.log(`RxdbService: collection "${name}" has "${parseInt(docsCount, 0)}" docs`);
    if (schemaConfig.options && schemaConfig.options.initialDocs && !!!docsCount) {
      const dumpObj = {
        name,
        schemaHash: collection.schema.hash,
        encrypted: false,
        docs: [...schemaConfig.options.initialDocs],
      };
      await collection.importDump(dumpObj);

rxdb

A local-first realtime NoSQL Database for JavaScript applications - https://rxdb.info/

Apache-2.0
Latest version published 6 days ago

Package Health Score

80 / 100
Full package analysis