Skip to content

Commit

Permalink
Open demo folder
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhduong committed Apr 25, 2018
1 parent 1001d4d commit 28b1865
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,4 @@ typings/
.env

dist
demo

69 changes: 69 additions & 0 deletions demo/typescript/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Queryable } from '../../dist';
const cTable = require('console.table');

let players = new Promise<{ name, overall, nationId, skills }[]>((resolve, reject) => {
// skills: attack, stamia, speed, shoot
console.log('get players...');
setTimeout(() => {
resolve([
{ name: 'Ronaldo', overall: 96, nationId: 1, skills: [96, 85, 87, 91] },
{ name: 'Messi', overall: 98, nationId: 2, skills: [97, 85, 91, 93] },
{ name: 'Mbappe', overall: 86, nationId: 3, skills: [89, 81, 95, 83] },
{ name: 'Matial', overall: 81, nationId: 3, skills: [81, 80, 89, 81] },
{ name: 'Salah', overall: 89, nationId: 4, skills: [88, 82, 97, 86] }
]);
}, 1000);
})

let nations = new Promise<{ id, name, areaId }[]>(resolve => {
console.log('get nations...');
setTimeout(() => {
resolve([
{ id: 1, name: 'Portugal', areaId: 1 },
{ id: 2, name: 'Argentina', areaId: 2 },
{ id: 3, name: 'France', areaId: 1 },
{ id: 4, name: 'Egypt', areaId: 3 }
]);
}, 2000);
})

let continents = new Promise<{ id, areaName }[]>(resolve => {
console.log('get continents...');
setTimeout(() => {
resolve([
{ id: 1, areaName: 'Euro' },
{ id: 2, areaName: 'South America' },
]);
}, 2300);
})

function main() {
let query = Queryable
.from(players)
.where(x => x.overall > 85);

let query1 = query.clone()
.join(nations, (x, y) => x.nationId === y.id)
.select(o => {
return {
playerName: o.x.name,
nation: o.y.name
}
});

let query2 = query.clone()
.select(o => {
return {
name: o.name,
realOverall: Queryable.fromSync(o.skills).avarage()
}
}).orderByDescending(x => x.realOverall);

query.toList().then(data => console.table(data));
query1.toList().then(data => console.table(data));
query2.toList().then(data => console.table(data));
}

main();


60 changes: 60 additions & 0 deletions demo/webpack/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Queryable } from '../../dist'

let players = new Promise((resolve, reject) => {
// skills: attack, stamia, speed, shoot
console.log('get players...');
setTimeout(() => {
resolve([
{ name: 'Ronaldo', overall: 96, nationId: 1, skills: [96, 85, 87, 91] },
{ name: 'Messi', overall: 98, nationId: 2, skills: [97, 85, 91, 93] },
{ name: 'Mbappe', overall: 86, nationId: 3, skills: [89, 81, 95, 83] },
{ name: 'Matial', overall: 81, nationId: 3, skills: [81, 80, 89, 81] },
{ name: 'Salah', overall: 89, nationId: 4, skills: [88, 82, 97, 86] }
]);
}, 1000);
})

let nations = new Promise(resolve => {
console.log('get nations...');
setTimeout(() => {
resolve([
{ id: 1, name: 'Portugal', areaId: 1 },
{ id: 2, name: 'Argentina', areaId: 2 },
{ id: 3, name: 'France', areaId: 1 },
{ id: 4, name: 'Egypt', areaId: 3 }
]);
}, 2000);
})

let continents = new Promise(resolve => {
console.log('get continents...');
setTimeout(() => {
resolve([
{ id: 1, areaName: 'Euro' },
{ id: 2, areaName: 'South America' },
]);
}, 2300);
})


function main() {
// Just query not execute query
console.time('querytime');
let query =
Queryable.from(players)
.join(nations, (x, y) => x.nationId === y.id)
.select(o => {
return {
name: o.x.name,
realOverall: Queryable.fromSync(o.x.skills).avarage()
}
})
.orderBy(x=>x.realOverall);

query.toList().then(data => {
console.log(data);
console.table(data)
})
}

main();

0 comments on commit 28b1865

Please sign in to comment.