Giter Site home page Giter Site logo

relational-pouch's People

Contributors

akofman avatar broerse avatar bterkuile avatar dependabot[bot] avatar egoossens avatar floer32 avatar garrensmith avatar gr2m avatar jkleinsc avatar jlami avatar larsjk avatar msenevir avatar mshick avatar nolanlawson avatar nruth avatar rsutphin avatar stevebest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

relational-pouch's Issues

Can't find an object if one of it's 'belongsTo' parents doesn't reference it anymore.

When a relation is broken, it's not even possible to find the child element anymore.
I agree that relations shouldn't get broken, but I'm not sure this is the best behaviour.
Perhaps only returning the object, without it's parent would be better.

describe('broken relation test', function() {

    var testPouch2;

    before(function() {

        var authorModel = {
            singular:'author',
            plural:'authors',
            relations:{
                books:{hasMany:'books'}
            }
        };
        var bookModel = {
            singular:'book',
            plural:'books',
            relations:{
                author:{belongsTo:'author'}
            }
        };
        var librarySchema = [authorModel, bookModel];
        testPouch2 = new PouchDb('https://user:[email protected]/library');
        testPouch2.setSchema(librarySchema);

        var john = {
            name:'John Doe',
            books: [
// Breaking the relation, 'ISBN12341234',
            'ISBN5759759'
            ],
            id:'jdoe'
        };
        var book1 = {
            title:'Great book',
            id:'ISBN5759759',
            author:'jdoe'
        };
        var book2 = {
            title:'Awesome book',
            id:'ISBN12341234',
            author:'jdoe'
        };

        return testPouch2.rel.save('book', book1)
        .then(function() {
            return testPouch2.rel.save('book', book2);
        })
        .then(function() {
            return testPouch2.rel.save('author', john);
        });             

    });

    it('should return at least the book that we\'re looking for', function() {
        return testPouch2.rel.find('book', 'ISBN12341234')
        .then(function(books) {         
            expect(books['books'][0].id).to.equal('ISBN12341234');
// This fails because only the author and the book it references are returned.
        });
    });
});

Just curious what you're opinion is on this behaviour.
I'll try submitting a PR if I find the time to dive into the rel#find method's code.

How to upsert with relational Pouch ?

Hello,

here is what I tried, but unfortunately I encounter sometimes an infinite loop of 409 errors....
Example on angular with $q.

Can you help me to improve upserting with relational-pouch ?

          var deltaFunc = function (doc) {
                doc.counter = doc.counter || 0;
                doc.counter++;
                return doc;
            };

            //upsert when a db.rel.save catch a 409 error.
            var upsert = function(doc, type) {
                return $q.when(db.rel.find(type, doc.id))
                    .then(function (result) {
                        var firstProperty = Object.keys(result)[0];
                        var doc2 = result[firstProperty][0]; // I get the doc here.
                        console.warn(doc.rev, doc2.rev);
                        console.warn(doc, doc2);
                        if(doc.rev != doc2.rev){
                            doc.rev = doc2.rev;
                            doc = deltaFunc(doc);
                            return tryAndPut(doc, type);
                        }else{
                            console.log("SAME Revisions !! :( ");
                            delete doc.rev; // rev deletion for a fresh save in order to create a new REV.
                            doc = deltaFunc(doc);
                            return tryAndPut( doc, type, del);
                            //return $q.when(factory.localDB.rel.find(type, doc.id)); (invetigating)
                        }
                    })
                    .catch(function (err) {

                        if (err.status !== 404) { // some error other than "not found"
                            throw err;
                        }
                        console.error(err);
                        return {_id : doc.id}; // default doc
                    });
            };


            var tryAndPut = function(doc, type) {
                console.log("tryAndPut", doc);
                return $q.when(db.rel.save(type, doc))
                    .catch(function (err) {
                        if (err.status !== 409) { // some error other than "conflict"
                            console.error("some error other than conflict",err);
                            throw err;
                        }else{
                            console.error("tryAndPut",err);
                            return upsert(doc, type, del);
                        }
                    }).then(function(res){
                        console.log("SUCCESS RE-SAVE "+ type +" OK",  res );
                        return res;
                    });
            };

How to set async option for individual method calls?

In the docs, it's possible to set async to true or false in the setSchema method:

books: {hasMany: {type: 'book', options: {async: true}}}

But how can I set it to false for individual method calls like find?

For example:

// In some cases I want to use async: false
db.rel.find('books', {async: false});

// and in other cases I want to use async: true
db.rel.find('books', {async: true});

Sync issues with attachments on IE 10

Hello,

I am building an Ionic app using this plugin to store my data.
I came across a problem when replicating an attachment, containing a base64string of a picture.
First, i add an attachment to the pouchdb, then, i try to replicate the attachment to a remote CloudantDB which returns an error.

In andoid or IOS, everything works fine, but when i try to replicate an attachment on an IE10 device, an error occurs.

The only logging i am getting is the following:
@dbService | syncData | Error while replicating data to Remote Db
ERROR: Object doesn't support property or method 'readAsBinaryString'

I execute following code after i saved my attachment:
Db.getDb().replicate.to(Db.getRemoteDb()).on('complete', function (result) { console.log('@dbService | syncData | Data replicated to Remote Db'); }).on('error', function (error) { console.log('@dbService | syncData | Error while replicating data to Remote Db'); console.log('ERROR: ' + error); });

I also retrieve the following logging when i try to replicate the attachment but I totally dont understand how the filereader plugin might possibly have anything to do with this issue.
Exception was thrown at line 267, column 9 in ms-appx://be.axi.sramvp1/www/plugins/cordova-plugin-file/www/FileReader.js 0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'readAsBinaryString'

To summarize, saving the attachment to the pouchdb just works fine. Only replicating to the remote cloudantDB doesn't work.

If anyone else came across this issue, please let me know.

Thanks in advance

Performance of loading a lot of results

First of all - thanks for this plugin. It may be really useful, especially for local DBs on mobile devices, where it allows to limit the stored data, compared to "one big object" approach.

I have a use case that requires some more logic - we retrieve all objects, to run a filter function on them and use only a subset. RelationalPouch queries all objects with all their relations and so on, so the resulting memory usage and execution time become too significant.

I have made a fork that tries to solve this issue, by allowing an array of constraints: https://github.com/bamlab/relational-pouch/tree/feature/where-and-join
The solution can be extended/improved but this is the first idea. It could be further extended to only retrieve selected relations, hence the branch name.

Could you give me some feedback? What do you think of the problem itself and my proposed solution?

Use Relational Pouch with requirejs

Hi,

I am new to PouchDB and requirejs and would like to use Relational Pouch with requirejs. Unfortunately I always get the error: 'Uncaught TypeError: undefined is not a function' as soon as I want to use a relational pouch function. Looks like relational pouch is not not accessible, although it is is being loaded.

Here is my code: https://github.com/Iomegan/Pouchpouchdb-plugin-requirejsD/blob/master/scripts/client.js (and a test project)

Does Relational Pouch even work with requirejs? PouchDB alone works fine with.

Fewer HTTP requests

Right now it makes a lot. For local it doesn't matter, but for remote CouchDBs, it can be a drag.

Readme file info about find/save and find/del pattern inaccurate

Forgive me if I missed something, but it seems I can't reproduce the find/save and find/del patterns described in the Readme file.
The find method returns a collection object even when specifying an id. Shouldn't the first item be extracted before it can be fed to the del/save method?

db.rel.find('post', 1).then(function (post) {
  return db.rel.del('post', post.posts[0]).catch(function (err) {
    if (err.code === 409) { // conflict
      // handle the conflict
    } else {
      throw err; // some other error
    }
  });
});

Saving a doc with inner objects behavior

Suppose we have a javascript object with a inner object that we want to save as a doc in pouchdb . In my case it has more lines and a couple of relationships, but for simplicity :

{
  id : "doc1",
  name : "Document 1",
  props : {
    id : 1,
    prop1 :  "hello",
    prop2 : "world"
  }
}

In normal pouch, we can put this to save a doc like:

Image of normal pouchdb

But, if when we try to save with db.rel.save, it only stores the id of object, skipping all other content:
Image of relational-pouchdb

If before call db.rel.save, I do doc.props = [doc.props]; it will be stored as an array with the entire object. It has a big side effect doing this when we retrive in client, console.log($scope.doc) prints all doc correclty (including prop as an array with one object), but doing console.log($scope.doc.props) throws undefined.

So, what's happening when saving an object inside doc? It is the normal behavior?

factory.db.rel.del & PouchDB Sync

Hello,
Thank you for your work !

I have an issue with factory.db.rel.del
When I delete with this function I guess it's normal that in the PouchDatabase Document Store
The document get a "deleted":true

And In the Sync CouchDB Database I can see the datas disapear.

But they stay in the local PouchDB with "deleted":true.

and Unfortunately, I cannot re-save the same objects
I have a ""Document update conflict", Error 409

Even if those docs were deleted before

Add a query method to allow chaining from ember-pouchdb/query

First, thanks a lot for the tool set you put together.

I feel like query in ember-pouch is broken. I amend your tests and the relational context is lost (querying smasher also returns tacoSoup)
cf.

This issue lead me here where I would like to add a query method to call from ember-pouchdb instead of the db.find() which can returned not relationally valid data.

I am currently giving it a go and will probably create a PR soon.

docs: removeAttachment readme say it adds an attachment

I think there's a typo in the readme

db.rel.removeAttachment(type, object, attachmentId)

Adds an attachment to the given object. Returns a Promise.

var attachment = new Blob(['Is there life on Mars?']); // new Buffer('Is there life on Mars?') for node
db.rel.putAttachment('post', {id:1, rev:"1-0560dbb11ead319c9f5bc1f667ea8e84"}, 'file', attachment, 'text/plain').then(function (res) {
  var post = res.posts[0];
  db.rel.removeAttachment('post', post, 'file');
});

Result:

{
  "posts": [
    {
      "id": 1,
      "rev": "3-...."
    }
  ]
}

I don't really know what this does, but it seems like it should say remove instead of add, and I don't know if the result example is right or needs editing.

Why adding id type to id string?

In the serialize function, id type added to id parameter. Why this is necessary?
I think it's for the find function.

function serialize(type, id) {
  // simple collation that goes like this:
  // undefined < numbers < strings < object
  var res = type.replace('_', '') + '_';
  if (typeof id === 'number') {
    // zpad
    id = id.toString();
    while (id.length < MAX_INT_LENGTH) {
      id = '0' + id;
    }
    res += TYPE_NUM + '_' + id;
  } else if (typeof id === 'undefined') {
    // need lowest possible value
    res += TYPE_UNDEF;
  } else if (typeof id === 'object') {
    // need highest possible value
    res += TYPE_OBJ;
  } else { // string
    res += TYPE_STRING + '_' + id;
  }
  return res;
}

Implement getById method, or expose serialize function

I was trying to put together a convenience/wrapper method in my app that just returns the requested object -- to make the data structure easier to work with for editing and other situations I would prefer only having the necessary object, rather than an object with embedded array and relations ( i.e., { posts: [ { id: 1} ] } ). The docs actually refer to a non-existent method db.rel.get for cases where you need the doc revision to perform a delete.

Having access to the internal serialize function in some form would allow me to build my own method using a basic db.get (the serialize scheme is easy enough, but I would rather not reimplement it in my app code). It could also be wrapped up to be symmetrical with parseDocID like:

var id1 = 'post_1_abc123'
var id2 = db.rel.makeDocID(db.rel.parseDocID(id1));
id1 === id2 // true

I also noticed the Ember DS.Store class has a getById(type, id) method, so perhaps there are other ways you might want to implement functionality like this that do not involve exposing serialize.

I could do a PR for a makeDocID method, but being newbish with this module getById might be a bigger challenge right now.

FindHasMany is limited to 25 (default) hits

When using ember-pouch (or relational-pouch), when following a hasMany link, it doesn't set an unlimited limit, so I only get the first 25 children

For instance when listing all managers, that have a managerFor relation to technicians (inverse via manager) results in a _find where manager = the id. However, since no limit is included, I only ever get the 25 first technicians for the manager.

The code in question is: https://github.com/pouchdb-community/relational-pouch/blob/master/lib/index.js#L425-L438

Many-to-many relationships pulling too many documents

First of all, I started testing pouchdb in an ionic 2 proof of concept app only a few days ago, so my knowledge is very limited (and I started to evaluate relational-pouch about 2 hours ago...)

I created the following schema (which, if I am not mistaken, should be a many-to-many relation):

           {
                "singular": "department",
                "plural": "departments",
                "relations": {
                    "checklists": { "hasMany": "checklist" }
                }
            }, {
                "singular": "checklist",
                "plural": "checklists",
                "relations": {
                    "departments": { "hasMany": "department" }
                }
            }

I created 10 'department' documents of the form { id: 1 ... 10, checklists: [1], ... }
I created 1 checklist: { Id: 1, departments: [1,2,3,4,5,6,7,8,9,10], ... }

When running the query db.rel.find('department', [1,3,5,7,9]), all departments (id: 1 to 10) are returned (the single checklist is also returned, which is expected).
This is not the behavior I expected. It seems that because the checklist points to all departments, the departments are pulled along even if they are not in the query list of ids. If I modify the checklist to { id: 1, departments": [1,3,5,7,9] } to match the query, then it "works" (meaning only departments with ids 1,3,5,7,9 are returned).

Not sure if I am doing something wrong, if it's a bug, or if it's by design. Is there a way to limit documents to what was requested in the list of ids?

Is possible validate the integrity of data in a relationship?

Is possible validate the integrity of data in a relationship?

For example, in the documentation, an author has many books.

db.setSchema([
  {
    singular: 'author',
    plural: 'authors',
    relations: {
      'books': {hasMany: 'book'}
    }
  },
  {
    singular: 'book',
    plural: 'books',
    relations: {
      'author': {belongsTo: 'author'}
    }
  }
]);

If I add an author with a book code that does not exist. Is possible validate?

db.rel.save ('author', {
   name: 'Stephen King'
   id: 19
   books: [100]
}) ....

In this case, the item 100 does not exist.

Thank you.

Search with multiple fields or selectors

Hi
I am not able to search with multiple fields like (name,description) by using this plugin as we can do with pouchdb-find plugin but that plugin is also not working as relation-pouch is saving data in one field in JSON form.

is there any way to do it ?

Unprefixed ids

This question is related to this.

I'm converting data between a pre-existing flat format and the nested data key which is used by relational pouch using transform-pouch which works great, but the issue I'm seeing is that relational-pouch expects all _ids to be prefixed with (in my case) note_2_.

None of the existing data follows this convention, they all just use standard uuids. Converting the id's with transform-pouch does not help here, presumably because relational-pouch relies on the prefix to lookup data. Is there any way around this which does not involve migrating the ids of all my existing data?

Perhaps I should be writing a PR to transform-pouch to add handlers which only apply to replication?

Can not query documents

Hey guys, how to fix this?

Input

db.rel.find('author')

output

(node:57648) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: db.find is not a function
(node:57648) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code

db.rel.find doesn't have an option return attachments (only metadata)?

Hi guys,

I am trying to fetch all the items with its attachments using db.rel.find. I've tried to add an option but no luck.

db.rel.find('post', { attachments: true })

I know there's a way to get attachments by using db.rel.getAttachment(type, id, attachmentId). But this one only gets an attachment of a single item.

Handle relations when deleting/updating an object.

I didn't inspect the code to know whether it is possible but would that make any sense to handle relations when deleting or updating an object ?

For instance, if we have a one-to-many relation between books and an author, If we delete one of these books, we should also remove its reference from the books array in the artist object.

Thoughts ?

Expose serialize and deserialize methods for the keys

So you can connect pouch relational directly to couchdb, where the docs are not stored in the same database, but in there own database. So the type is not automatically added to the id, if for instance the db adapter is 'http'.

PouchDB v5.4.5

I get an exception Cannot read property 'Promise' of undefined from pouch-utils.js when I upgrade to the latest version of PouchDB:

Promise = window.PouchDB.utils.Promise

Multiple relations possible?

Would something like this work (especially the relations between obj and objList):

let schema = [
            {
                singular: 'obj', plural: 'objs', relations: {
                'objList': { belongsTo: 'objList' },
                'attributesEditable': { belongsTo: 'attributesEditable' },
                'attributesViewable': { belongsTo: 'attributesViewable' },
            },
            },
            {
                singular: 'objList', plural: 'objLists', relations: {
                'objs': { hasMany: 'obj' },
                'obj': { belongsTo: 'obj' },
            },
            },
            {
                singular: 'attributesEditable', plural: 'attributesEditables', relations: {
                'obj': { belongsTo: 'obj' },
            },
            },
            {
                singular: 'attributesViewable', plural: 'attributesViewables', relations: {
                'obj': { belongsTo: 'obj' },
            },
            },
        ];

What I want:
image

My App starts with an entry point which is an obj and this has one objList with many obj in it and so on.

Addition of a flag in the schema to define local types

It may be a bit convoluted but it would be nice to specify a type that is local only in the schema so that the schema can be shared and sync-ed partially.

My issue case: I would like to create a user model with attributes. I would to take advantage of pouch features but I don't want user attributes to be synchronised the usual way (instead I want to rely on pouch-auth to update the _users record).

Working in Ember, if that's a feature worth exploring, it will be great to have that available in Ember-pouch.

Let me know what your thoughts are before I dig into the potential implementation.

Thanks

plugin not compatible with requirejs

Recently attempted to add local storage with ember-pouch which depends on relational-pouch. My project is using requirejs and no matter what I attempted, loading this plugin through require would not function.

Removing all references to requirejs and simply including this library as <script inside the page has cured the issue.

Modeling a rooted tree graph

Hi there,

I'm exploring some options for how I'm going to structure the related data in my PouchDB / CouchDB database, and I'm struggling to understand the limits of what relational-pouch can do in my use case. I suspect that this is way out of scope for what relational-pouch was built to handle, but I wanted to make sure.

I was unsure whether this heading alluded to what I'm trying to do or not.

Basically, let's assume my data model has 30-40 document types, any of which can have a parent_id that links them to exactly one parent document, of an arbitrary type, in a non-cyclic fashion. For any given document, if I follow the chain of parent_ids all the way to its end, I'll reach a common ancestor (the root).

If I query relational-pouch for a leaf document, can / will relational-pouch automatically, recursively, side-load all the ancestors in the response? Or will I need to do that at the application level?

How would I handle a situation where I need to delete a non-leaf node? If I don't save the relationship bi-directionally (since that would lead to parent nodes getting hammered with revisions), how would I go about re-linking all those descendants to the deleted document's parent?

Here's an example that might help illustrate the situation I'm grappling with:

// root node that everything points back to
{ _id: "country_1", type: "country"}

// children of root
{_id: "state_1", type: "state", parent_id: "country_1"}
{_id: "state_2": type: "state", parent_id: "country_1"}

// grandchildren of root
{_id: "city_1": type: "city", parent_id: "state_1"}
{_id: "city_2": type: "city", parent_id: "state_1"}
{_id: "city_3": type: "city", parent_id: "state_2"}
{_id: "city_4": type: "city", parent_id: "state_2"}

// assets of various types can belong to federal, state or municipal entities
// these would be either children, grandchildren or great-grandchildren of root
{_id: "asset_a_1", type: "asset_a", parent_id: "country_1"}
{_id: "asset_a_2", type: "asset_a", parent_id: "state_2"}
{_id: "asset_b_1", type: "asset_b", parent_id: "city_3"}
{_id: "asset_b_2", type: "asset_b", parent_id: "city_2"}
{_id: "asset_b_3", type: "asset_b", parent_id: "city_2"}
{_id: "asset_c_1", type: "asset_c", parent_id: "city_3"}
{_id: "asset_c_2", type: "asset_c", parent_id: "city_4"}
{_id: "asset_c_3", type: "asset_c", parent_id: "city_4"}

When I pull up asset_c_2, would relational_pouch resolve all the way back to country_1, or would it only resolve city_4?

If I wanted to delete state_2, this would orphan city_3, city_4, asset_a_2, asset_c_1, asset_c_2 and asset_c_3, since state_2 is their link to the root node. So, before deleting state_2, I would need to find all documents whose parent_id points to state_2 and link them to country_1. Can / does relational-pouch handle any of this logic, or would I need to do all of this myself?

My feeling is that, because the parent_id points to an arbitrary document type, relational-pouch probably can't handle this in the first place since you have to define belongsTo relationships by individual types in your schema. But I can't be the only person who's ever tried to model a graph in a *ouchDB. Is there a better-suited library I haven't heard of? Do I need to write my own?

P.S. Thanks for making ember-pouch work. It's saved me weeks of headaches :)

Navigation properties on returned entity

Hi,

I'd like to do something like: customer.customersource.name. Is this possible?

I know when I do db.rel.find('customer', 'my_id') it will return the customer and the related entities but it would be nice if it could also attach a property to the model for navigation purposes.

db.rel.find(type) not returning all data

For some reason, I'm not getting my full set of results when using this.

Are there any caveats to how this returns data? I've looked at the data in the database and it looks very similar to items that are being returned. The ids have the correct format i.e job_2_SOMEGUID.

I've done queries using pouch-find and get 170 results but only 144 with db.rel.find()

Object is deleted but still exist in database

Hello,
I tried to delete an object using this method:

delete(id){
    console.log("Id : " + id);
    this.db.rel.find('destination', id).then(doc => {
      return this.db.rel.del('destination', doc).then(data => {
        console.log(data);
      });
    });
  }

The result I get from the console:
{deleted: true}

But after I refresh the app the object appears again.

Handle cases where the database is in an inconsistent state

This can happen during replication, e.g. if a parent gets written before a child or a child gets written before a parent. I guess the proper thing to do would be to catch 404s and return nothing for that dependency.

I admit, though, that we are working against the grain of how CouchDB is designed.

Support to bulk operations

First of all, sorry for the inconvenience because I really dont know if this is an issue or an architecture decision not to offer bulk operations.

I am currently working with a large amount of documents and I found useful to keep the bulkDocs method supported by PouchDB. Why not exposing bulk save and bulk delete methods as described below?

  function _bulkSave(type, objs) {
    var typeInfo = getTypeInfo(type);
    var pouchDocs;
    return Promise.resolve().then(function () {
      pouchDocs = objs.map(function (obj) {
        return toRawDoc(typeInfo, obj);
      });
      return db.bulkDocs(pouchDocs);
    }).then(function (pouchRes) {
      var res = {};
      res[typeInfo.plural] = objs.map(function (obj, i) {
        return extend(true, obj, {
          id: deserialize(pouchRes[i].id),
          rev: pouchRes[i].rev
        });
      });
      return res;
    });
  }

  function _bulkDel(type, objs) {
    var typeInfo = getTypeInfo(type);
    var pouchDocs;
    return Promise.resolve().then(function () {
      pouchDocs = objs.map(function (obj) {
        var pouchDoc = toRawDoc(typeInfo, obj);
        return {
          _id: pouchDoc._id,
          _rev: pouchDoc._rev,
          _deleted: true
        };
      });
      return db.bulkDocs(pouchDocs);
    }).then(function () {
      return objs.map(function () {
        return {deleted: true};
      });
    });
  }

  function bulkSave(type, objs) {
    return Promise.resolve().then(function () {
      return _bulkSave(type, objs);
    });
  }

  function bulkDel(type, objs) {
    return Promise.resolve().then(function () {
      return _bulkDel(type, objs);
    });
  }

  db.rel = {
    bulkSave: bulkSave,
    bulkDel: bulkDel
  };

Also, I did some changes to ember-pouch adapter so it could use these bulk operations and accelerate insertions and deletions for large amount of data.

Thanks

db.rel.find(type, id) returns all 'type' docs, not only doc with that id.

Also happens with db.rel.find(type, ids). If you take the example from readme:

          var db = new PouchDB('mydb');
          db.setSchema([
              {singular: 'author', plural: 'authors', relations: { books: {hasMany: 'book'}}},
              {singular: 'book', plural: 'books', relations: {author: {belongsTo: 'author'}}}
          ]);
          db.rel.save('author', {
              name: 'George R. R. Martin', id: 1, books: [6, 7]
          }).then(function () {
              return db.rel.save('book', { title: 'A Game of Thrones', id: 6, author: 1});
          }).then(function () {
              return db.rel.save('book', {title: 'The Hedge Knight', id: 7, author: 1});
          }).catch(console.log.bind(console));

And then you want find book with id 7:

          db.rel.find('book',7).then(function(doc){
              console.log(doc);
          });

You got as result all books:

{
    "books" : [
        {
            "title" : "A Game of Thrones",
            "author" : 1,
            "id" : 6,
            "rev" : "1-16ce4f20eae39bd0655f00f81973dd14"
        },
        {
            "title" : "The Hedge Knight",
            "author" : 1,
            "id" : 7,
            "rev" : "1-7d35db00e3b7df172e33173eded5ab72"
        }
    ],
    "authors" : [
        {
            "name" : "George R. R. Martin",
            "books" : [
                 6,
                 7
            ],
            "id" : 1,
            "rev" : "1-c4c9b023321d67787d737421837988e3"
        }
    ]
}

Consider async relationship fetching

We are using the ember-pouch adapter and have two model: Category and Product.
Did some testing with 34 categories and a total of 1168 products. Fetching and parsing the categories is very slow because it fetches all the products as well.
Category fetch: 4.380ms
Product fetch: 2352.893ms
Parse: 2458.889ms

I really only need to load products when entering a category/:category_id route. Is it possible to load products async?

If not maybe fetching the all products with "startKey-endKey" and removing when parsing would be faster than a "keys:Array[1168]" fetch.

Explanation about docID

Hello,

It's more a question than an issue. I'd just like to understand what the meaning of the number between underscores when creating a DocID :

db.rel.makeDocID({ "type": "author", "id": 19 });
Returns:
"author_1_0000000000000019"

What the meaning of 1 ?

Thanks a lot.

How do I do sort on the relational data

Just curious what is the best way to support sorting ? ex. I have multiple comments on a blog, but when I find this blog, I'd like comments to be sorted by timestamp, how do I do this ? Thanks.

Merge 1.4.0 ?

Hello,

I just noticed that from the npm repo, the last version of this project is 1.4.0 which is different from the master branch. Would it be possible to merge it to master ?

I can't find any branch for this version, only a tag and it's not really convenient in order to compare, fork or fix properly some issues.

Thanks !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.