Skip to content

Select Distinct #23

@theRemix

Description

@theRemix

Allow the use of find() with distinct columns. examples:

model with static fields:

var model_static = {
    fields:{
        username: "text",
        name:{
            "type":"text",
            "static":true
        },
        surname:{
            "type":"text",
            "static":true
        },
        favorites:{
            "type":"text",
            "static":false
        },
        likes:"text",
    },
    key:[["username"],"favorites","likes"]
};
var TestFindDistinctModel = ap.add_model("testfinddistinct", model_static, );

insert 3 rows with static values:

var ins = new TestFindDistinctModel();
    async.series([
        function(callback){
            ins.username = 'ab';
            ins.name = 'a';
            ins.surname = 'b';
            ins.favorites = 'x';
            ins.likes = 'xx';
            ins.save(callback);
        },
        function(callback){
            ins.username = 'ab';
            ins.name = 'a';
            ins.surname = 'b';
            ins.favorites = 'y';
            ins.likes = 'yy';
            ins.save(callback);
        },
        function(callback){
            ins.username = 'ab';
            ins.name = 'a';
            ins.surname = 'b';
            ins.favorites = 'z';
            ins.likes = 'zz';
            ins.save(callback);
        }
    ],done);

find:

TestFindDistinctModel.find({},{ distinct : ['username','name','surname']},function(err, results){
  assert.lengthOf(results, 1);
  assert.propertyVal(results[0],'username','ab');
  assert.propertyVal(results[0],'name','a');
  assert.propertyVal(results[0],'surname','b');
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions