diff --git a/rethink-queries.md b/rethink-queries.md new file mode 100644 index 0000000..0e331a2 --- /dev/null +++ b/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'); +``` \ No newline at end of file