Skip to content
Dinh Duong edited this page Apr 25, 2018 · 1 revision

Queryable

  • .from => Promise<any>: All data source will be converted to Promise notwithstanding that source is Promise or noramlly array data. Then once we call toList(), count(), first()... or any execute methods it will be return a Promise.
let query = Queryable
           .from(nations)
           .join(continents, (x, y) => x.areaId === y.id)
           .groupBy(o => o.y.areaName)

const asyncData = query.count() // Will return Promise<number>
asyncData.then(num => {
   console.log(num);
   // 2
})
  • .fromSync => any: It's often use inside sub-query which are after all data already retrieved successfully or you make sure the input source is sync data like as Array.
let query = Queryable
            .from(nations)
            .join(continents, (x, y) => x.areaId === y.id)
            .groupBy(o => o.y.areaName)
            .select(x => {
                return {
                    area: x.key,
                    total: Queryable.fromSync(x.items).count() // Here will return number, not Promise<number>
                }
            })
const asyncData = query.toList() // Will return Promise<{area:string, total:number}>
asyncData.then(data => {
    console.log(data);
    // [
    //     {area: 'Euro': total: 2},
    //     {area:'South Ameria', total: 1}
    // ]
});

> More: at from method, all input sources at from, join, leftJoin methods,... will be converted to Promise and use Promise.all to execute and then use Iterator collection to query data and once faced excuting methods like as toList(), first() it will return data which be inside a Promise.

Clone this wiki locally