2 rethink queries
Big Bad Waffle edited this page 4 years ago
//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);
			});
	});

//Find all accounts with more than 1 Smoldering Idol in their stash
r.db('live').table('stash')
	.filter(row => {
		return row('value').ne(null).and(row('value').typeOf().eq('ARRAY'));
	})
	.concatMap(row => {
		return [{
			name: row('id'),
			cpn: row('value').filter(item => {
				return item('name').eq('Smoldering Idol').and(item('quantity').gt(1));
			})
		}];
	})
	.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');