-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
31 lines (26 loc) · 964 Bytes
/
example.js
File metadata and controls
31 lines (26 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import query from 'sql-js';
const rebels = [
{ name: 'Han', profession: 'Smuggler', age: 30 },
{ name: 'Luke', profession: 'Jedi', age: 32, father: 'Darth Vader' },
{ name: 'Leia', profession: 'Princess', age: 32 },
{ name: 'Obi', profession: 'Jedi', age: 65 },
{ name: 'Chewie', profession: 'Smuggler', age: 30 }
];
const empire = [
{ name: 'Anakin', profession: 'Jedi', age: 50 },
{ name: 'Darth Vader', profession: 'Lord Sith', age: 65 },
{ name: 'Lando', profession: 'Smuggler', age: 50 }
];
const fatherJoin = (join) => join[0].father === join[1].name;
const isJedi = (join) => join[0].profession === 'Jedi';
const age = (join) => join[0].age;
const older20 = (group) => group[0] > 20;
let resultSet = query()
.select()
.from(rebels, empire)
.where(fatherJoin)
.where(isJedi)
.groupBy(age)
.having(older20)
.execute();
console.log(JSON.stringify(resultSet));