Create rethink queries

master
Big Bad Waffle 4 lat temu
rodzic
commit
a04b0e5fe4
1 zmienionych plików z 72 dodań i 0 usunięć
  1. +72
    -0
      rethink-queries.md

+ 72
- 0
rethink-queries.md

@@ -0,0 +1,72 @@
```js
//Count the amount of permadead characters
r.db('live').table('character').filter({
value: {
permadead: true
}
}).count();

//Count the amount of permadead characters per spirit
r.db('live').table('character')
.filter({
value: {
permadead: true
}
})
.group(row => {
return row('value')('class');
})
.count();

//All players that are level 20
r.db('live').table('character')
.filter(row => {
return row('value')('components').contains(cpn => {
return cpn('type').eq('stats').and(cpn('values')('level').ge(20));
});
});

//Group by mod action source, aggregate and order by count
r.db('live').table('modLog')
.group(f => f('value')('source')).count().ungroup().orderBy('reduction');

//List Items with dex > 30
r.db('live').table('character')
.concatMap(row => {
return row('value')('components')
.filter(cpn => {
return cpn('type').eq('inventory');
})
.concatMap(c => {
return [{
name: row('value')('name'),
cpn: c('items').filter(item => {
return item('stats')('dex').ge(30);
})
}];
})
.filter(c => {
return c('cpn').count().ge(1);
});
});

//Play time per account from low to high
r.db('live').table('character')
.concatMap(row => {
return row('value')('components')
.filter(cpn => {
return cpn('type').eq('stats');
})
.concatMap(c => {
return [{
account: row('value')('account'),
name: row('value')('name'),
played: c('stats')('played')
}];
});
})
.group('account')
.sum('played')
.ungroup()
.orderBy('reduction');
```

Ładowanie…
Anuluj
Zapisz