Skip to content

Implment simpler interface for collections and references #9

@hal-gh

Description

@hal-gh

The approach shown in #5 (comment) is no doubt very versatile, but it seems to rely on data that already exists in the database and requires some existing knowledge of how the library works in order to use it.

The option to use an interface that supports the following construct that would make the learning curve very shallow and, consequently, allow far greater adoption.

// fixture object - single letter for brevity
var o = {};

// collections
o.families = {};
o.people = {};

// documents
o.families.smith   = { name: "Smith" };
o.families.jones   = { name: "Jones" };
o.families.connors = { name: "Connors" };
o.people.peter     = { name: "Peter", family: o.families.smith };
o.people.catherine = { name: "Catherine", family: o.families.connors, parents: [ { name: o.people.peter.name } ] };

console.log("Peter's family: " + o.people.peter.family.name);
console.log("Catherine's family: " + o.people.catherine.family.name);
console.log("Catherine's parent(s): " + o.people.catherine.parents[0].name);

Note how the collections are declared, which could be determined using lodash's _.keys(object) method).

Obviously, a full example showing self-references and references between collections where the data is purely described in text files or scripts would also be helpful after the implementation.

There maybe some benefit to separating the logic code and fixture data objects into separate files, to make it simpler to understand, possibly with them being loaded using async.series (already provided in a boilerplate).

This interface may well be quite difficult to implement or there may be some reasons you can think of why it wouldn't be practical or versatile which outweigh it's ease of use. If so, and if you do not object, I think it's worth discussing.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions