peerlibrary / meteor-peerdb

Reactive database layer with references, generators, triggers, migrations, etc.
http://atmospherejs.com/peerlibrary/peerdb
BSD 3-Clause "New" or "Revised" License
130 stars 15 forks source link

Anyway simpleschema, collection2 and peerdb can work together #17

Open emmanuelbuah opened 10 years ago

emmanuelbuah commented 10 years ago

First of all, I want to say kudos for putting in the work to get a reactive layer on top of mongo (server-side) to handle declarative updates. Both collection2 and simpleschema solve specific issues, same as peerdb. I personally see peerdb more of a better package to replace collection-hooks but I wonder if peerdb api can be made to work with collection2 and simpleschema. I really see 3 concerns here:

Data schema integrity and validation -> SimpleSchema Collection data schema validation on insert, upsert and update -> Collection2 Provide Collection data hooks on insert, upsert, update and delete -> Collection-hooks || Peerdb

I will personally like to use Peerdb over collection-hooks because of its reactive nature and the ability to handle hooks even if the changes are made by another client. For me peerdb is a clear winner but I cant seem to feel like it will even be much better if it can work in tandem with SimpleSchema and Collection2.

My question is - how do I get the benefit of simpleschema + collection2 + peerdb. Is it be possible to integrate all 3 to work together. Will it be better to integrate peerdb definitions into simpleschema since both of them are in a way defining metadata information. Example, If would be great if we could do something like


//data validation provided by simpleschema 
PostSchema = new SimpleSchema({
    content: {
        type: String,
        optional: false,
    },
   author: {
     type:Object,
     optional: false
   },
   "author.username": {
      type: String
  },
   "author.displayName": {
      type: String
  },
   hits: {
        type: Number
    }
   //etc
});

//peerdb hook through SimpleSchema
PostSchema.References({
    fields: function() {
      return {
        author: Post.ReferenceField(Person, ['username', 'displayName']),
      };
    }
  });

PostSchema.Triggers({
    //trigger definition here ....
  });

Post = new Meteor.Collection('posts');
Post.attachSchema(PostSchema); //provided by collection2

In the approve sample code, simpleschema handles validation (i.e. make sure author's username and displayname is a string), collection2 handle running validation and peerdb extension to simpleschema + collection2 maintains data references and hooks. This is just a thought but I think something along these lines will provide the community with 80% of what its needed for data manipulation. I want to use peerdb now but I also don't want to loose my schema validation checks on my collection (as well as on the client through autoform)

mitar commented 9 years ago

What do you mean? You probably don't check in your template helper if document returned from the client-side copy of data has the document you are searching for. You render templates before all data is available.

mitar commented 9 years ago

I am trying to create some benchmarks and it would be useful to learn about db schemas people use PeerDB for. Care to share?

lonniev commented 7 years ago

Reading @PiTopRyan's Nov 2014 remarks, I infer that he was able to use SimpleSchema with PeerDB to offer at least simple schema input validations while using PeerDB collections. This is a valid inference?

@lonniev is very new to meteor and peerdb...