pubkey / rxdb

A fast, local first, reactive Database for JavaScript Applications https://rxdb.info/
https://rxdb.info/
Apache License 2.0
21.37k stars 1.04k forks source link

ReferenceError: regeneratorRuntime is not defined #116

Closed ralyodio closed 7 years ago

ralyodio commented 7 years ago
async function createDb(){
  const RxDB = require('rxdb');
  RxDB.plugin(require('pouchdb-adapter-websql'));
  const db = await RxDB.create({
    name: 'testdb',
    adapter: 'websql',
    password: 'asdfasdf', // optional
    multiInstance: true                  // default: true
  });

  const mySchema = {
    disableKeyCompression: true,
    version: 0,
    title: 'things schema',
    type: 'object',
    properties: {
      title: {
        type: 'string'
      },
      link: {
        type: 'string'
      },
      date: {
        type: 'date'
      }
    },
    required: ['title', 'link']
  };

  return await db.collection({name: 'things', schema: mySchema});    // create collection
}

I get an error when running this: ReferenceError: regeneratorRuntime is not defined

I'm using node v7.7

pubkey commented 7 years ago

I think you forgot the polyfills

require("babel-polyfill");
ralyodio commented 7 years ago

Do I need that? I only want to use native node v7 not babel.

If I add that I get a different error:

Error: Adapter websql not added.
                 Use RxDB.plugin(require('pouchdb-adapter-websql');

its installed. :|

pubkey commented 7 years ago

You are right. I will inspect.

pubkey commented 7 years ago

Btw Websql does not work in nodejs. You need another adapter here

ralyodio commented 7 years ago

I'm new, just following the getting started. What adapter should I use with node.js?

I like the example I posted, with a jsonschema and an object. But I'm not sure what I should be using if not websql.

ralyodio commented 7 years ago

I think we need a node.js example: https://github.com/pubkey/rxdb/tree/master/examples

I'm confused. Does this library not work with node.js?

pubkey commented 7 years ago

Yes, this lib works with nodejs. All tests run in nodejs and the browsers :) Yes we need a nodejs example. To play around I recommend the memory-adapter. For persistent storage use the leveldb-adapter.

leveldown = require('leveldown'); leveldb = require('pouchdb-adapter-leveldb'); RxDB.plugin(leveldb);

pubkey commented 7 years ago

@chovy I inspected the issue. I'm sorry, but for some reason you need the babel-polyfill at the moment, the build does not include the runtime-regenerators.

Here is a working example with rxdb and leveldown.

npm i rxdb rxjs babel-polyfill pouchdb-adapter-leveldb leveldown --save
require('babel-polyfill');

const RxDB = require('rxdb');
RxDB.plugin(require('pouchdb-adapter-leveldb'));
const leveldown = require('leveldown');

async function createDb() {
    const db = await RxDB.create({
        name: './testdb',
        adapter: leveldown, // leveldb-adapters must be passed directly instead of the name
        password: 'asdfasdf', // optional
        multiInstance: true // default: true
    });

    const mySchema = {
        disableKeyCompression: true,
        version: 0,
        title: 'things schema',
        type: 'object',
        properties: {
            title: {
                type: 'string'
            },
            link: {
                type: 'string'
            },
            date: {
                type: 'date'
            }
        },
        required: ['title', 'link']
    };

    await db.collection({
        name: 'things',
        schema: mySchema
    }); // create collection

    console.dir(db.things);

    return;
}

async function run(){
  await createDb();
}

run();
ralyodio commented 7 years ago

I have a pouchdb server, can I point to that? When I run this example code it seems to create its own database in the current directory.

pubkey commented 7 years ago

I'm sorry, but you can not just use the same folder. If you want to use pouch-server-data with rxdb, you have to sync.