JsStore supports two joins - Inner & Left.

Sql (inner join between two tables)

Select * From Table1;
Inner Join Table2
On Table1.common_field = Table2.common_field
Where
Table1.Column1=some_value
And
Table2.Column1=some_another_value

JsStore

var results = await connection.select({
    from: table1 name,
    where: {
        [column name]: some value
    },
    join: {
        with: table2_name,
        on: "table1.common_field=table2.common_field",
        type:"inner",
        where: {
            [column name]: some value
        }
    }
});
console.log(results);

Note :- you can also use - WhereIn, Skip, Order By and limit just like where has been used in the above example.

Example

join has following properties -

  • with : string // name of table to join

  • on : string // join condition eg - table1.property = table2.property

  • as : object // rename some column name in order to avoid the column match with other tables

e.g - if a column customerId is present in both table, then a column match error will be thrown & in this situation you can use as to resolve the error.

connection.select({
    from: table1 name,
    join: {
        with: table2_name,
        on: "table1.common_field=table2.common_field",
        as: {
            customerId: table2_customerId
        } 
    }
});
  • where // to filter

  • order // for ordering data - but unlike query without join, order here is little different. You need to provide query along with table name in the form of [tablename].[columnName]

  • groupBy // for grouping

  • aggregate // aggregation of data

Sql (inner join between three tables)

Select * From Table1;
Inner Join Table2
On Table1.common_field = Table2.common_field
Inner Join Table3
On Table1.some_column = Table3.some_common_column

JsStore

var results = await connection.select({
    from: table1_name,
    join:[{
        with:table2_name,
        on: "table1.common_field=table2.common_field"
    },{
        with:table3_name,
        on: "table1.common_field=table3.common_field"
    }]
});
console.log(results);

Example