-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Dinh Duong edited this page Apr 25, 2018
·
1 revision
-
.from
=>Promise<any>
: All data source will be converted toPromise
notwithstanding that source is Promise or noramlly array data. Then once we calltoList()
,count()
,first()
... or anyexecute methods
it will be return aPromise
.
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 asArray
.
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 atfrom, 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 astoList(), first()
it will return data which be inside a Promise.