-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathevents.js
79 lines (75 loc) · 1.84 KB
/
events.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const { Table } = require('rethink-table')
module.exports = async con => {
const schema = {
table: 'events',
indices: ['created', 'type', 'provider', 'userid', 'timeframe'],
compound: [
{
//Compound index
name: 'provider_userid',
fields: ['provider', 'userid'],
},
{
//Compound index
name: 'provider_timeframe_userid',
fields: ['provider', 'timeframe', 'userid'],
},
],
}
const table = await Table(con, schema)
return {
...table,
changes() {
const query = table.table().changes()
return table.streamify(query)
},
streamSorted() {
const query = table.table().orderBy({ index: 'created' })
return table.streamify(query)
},
listSorted() {
const q = table
.table()
.orderBy({ index: table.r.desc('created') })
.limit(1000)
.coerceTo('array')
return table.run(q)
},
listUserSorted(userid) {
const query = table
.table()
.orderBy({ index: 'created' })
.filter({ userid })
.limit(1000)
.coerceTo('array')
return table.run(query)
},
listIndexSorted(index, value) {
const query = table
.table()
.orderBy({ index: 'created' })
.filter({ [index]: value })
.limit(1000)
.coerceTo('array')
return table.run(query)
},
listGroups(index) {
const q = table
.table()
.group({ index })
.count()
return table.run(q)
},
// listTopSites() {
// const query = table
// .table()
// .getAll('case-opened', { index: 'type' })
// .group('caseOpeningSite')
// .count()
// .ungroup()
// .orderBy(table.r.desc('reduction'))
// .limit(100)
// return table.run(query)
// },
}
}