fordth / jinqJs

jinqJs provides a simple way to perform SQL like queries on javaScript arrays, collections and web services using LINQ expressions.
Other
93 stars 29 forks source link

Allow for None to Single/Many Joining #1

Closed neelneelneel closed 9 years ago

neelneelneel commented 9 years ago

Allow for None to Single/Many Joining to be outputted after join.

Say I run the sample code:

    var people = [{
        Name: 'Jane',
        Age: 20,
        Location: 'Smithtown'
    }, {
        Name: 'Ken',
        Age: 57,
        Location: 'Islip'
    }, {
        Name: 'Tom',
        Age: 10,
        Location: 'Islip'
    }];

    var population = [{
        Location: 'Islip',
        People: 123
    }, {
        Location: 'Melville',
        People: 332
    }, ];

    var result = jinqJs()
        .from(people)
        .leftJoin(population)
        .on(function(left, right) {
            return (left.Location === right.Location);
        })
        .select();

The output is:

[{
    "Name": "Jane",
    "Age": 20,
    "Location": "",
    "People": ""
}, {
    "Location": "Islip",
    "People": 123,
    "Name": "Ken",
    "Age": 57
}, {
    "Location": "Islip",
    "People": 123,
    "Name": "Tom",
    "Age": 10
}]

However, I expect the output to be a merge of data sets:

[{
    "Name": "Jane",
    "Age": 20,
    "Location": "",
    "People": ""
}, {
    "Location": "Islip",
    "People": 123,
    "Name": "Ken",
    "Age": 57
}, {
    "Location": "Islip",
    "People": 123,
    "Name": "Tom",
    "Age": 10
},{
    "Location": "Melville",
    "People": 332,
    "Name": "",
    "Age": ""
}]

I have it working with lodash, but the solution is inefficient for large datasets.

fordth commented 9 years ago

Hey nsang92, thanks for your feedback. Using the leftJoin is producing an outer join on the collection in the .from() function. So the behavior of the results that you are seeing are expected. But I do understand your point about a "merge" many join. I will plan to implement that in the next coming version or following one. I will keep you posted. Thanks again :)

fordth commented 9 years ago

There is a way to perform a full join and get the results you are looking for until I include a full join in the next version. You can see this Fiddle http://jsfiddle.net/tford/7zr2n4f0/ which has jinqJs performing two outer joins and then a union to get your results.

neelneelneel commented 9 years ago

Hey, thank you! I'll look foward to full join in the next verwion.