Order By
Order By is used to sort the data in ascending or descending order, based on any column.
Sql
Select * from Table_Name Order by column_name sort_type;
JsStore
var results = await connection.select({
from: "Table_Name",
order: {
by: column_name,
type: sort_type //supprted sort type is - asc,desc
}
});
//results will be array of objects.
console.log(results);
Option
Order has following options -
by: string; // sorting column name
type: string; // sorting type - asc/desc, default is asc
idbSorting: boolean // whether to do sorting by indexeddb or by jsstore, default - true
By multiple column
For ordering by multiple column - you need to provide all order object value in an array
var results = await connection.select({
from: "Table_Name",
order: [{
by: column_name1,
type: sort_type //supprted sort type is - asc,desc
},
{
by: column_name2,
type: sort_type //supprted sort type is - asc,desc
}]
});
//results will be array of objects.
console.log(results);
In join
Unlike query without join, order here is little different. You need to provide query along with table name in the form of [tablename].[columnName]
select({
from: "Student",
join: {
with: "StudentDetail",
on: "Student.Name=StudentDetail.Name"
},
order: { by: 'Student.Order', type: 'asc' }
})