Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhduong committed Apr 23, 2018
1 parent a03c160 commit 7fdab15
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,53 @@

### Example
```js
import { Queryable } from "./implements/queryable";
import { Queryable } from "../implements/queryable";

const queryable = new Queryable<{ name, overall }>();
const queryable = new Queryable<{ name, nationId, overall, skills }>();

let promiseApi = new Promise((resolve, reject) => {
// Fake data from api
setTimeout(() => {
console.log('...get data');
resolve([
{ name: 'Ronaldo', overall: 96 },
{ name: 'Messi', overall: 98 },
{ name: 'Mbappe', overall: 86 },
{ name: 'Ronaldo', overall: 96, nationId: 1, skills: [97, 90, 86, 95] },
{ name: 'Messi', overall: 98, nationId: 2, skills: [97, 90, 86, 95] },
{ name: 'Mbappe', overall: 86, nationId: 3, skills: [97, 90, 86, 95] },
{ name: 'Salah', overall: 89, nationId: 4, skills: [97, 90, 86, 95] }
]);
}, 3000);
}, 1000);
})

let staticLoopkup = [
{ id: 1, name: 'Portugal', areaId: 1 },
{ id: 2, name: 'Argentina', areaId: 2 },
{ id: 3, name: 'France', areaId: 1 },
{ id: 4, name: 'Egypt', areaId: 3 }
]

let staticAreas = [
{ id: 1, areaName: 'Euro' },
{ id: 2, areaName: 'South America' },
]

async function main() {
// Just query not execute query
let query = queryable
.from(promiseApi)
.where(x => x.overall > 90);
.join(staticLoopkup, (x, y) => x.nationId == y.id)
.select((o) => {
return {
playerName: o.x.name,
overall: o.x.overall,
nation: o.y.name
};
})
.orderBy(x => x.playerName);

const count = await query.count();
console.log(count)
// 2

let query1 = query
.where(x => x.overall > 96)
.select(x => `Best player is ${x.name}`);
const data = await query.toList();
console.log(data);

const num1 = await query1.toList();
console.log(num1)
// ['Best player is Messi']
}

main();
Expand Down

0 comments on commit 7fdab15

Please sign in to comment.