-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathtickers.js
39 lines (36 loc) · 872 Bytes
/
tickers.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
const { Table } = require('rethink-table')
module.exports = async con => {
const schema = {
table: 'tickers',
indices: ['created', 'type'],
}
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(100)
.coerceTo('array')
return table.run(q)
},
listUserSorted(userid) {
const query = table
.table()
.orderBy({ index: 'created' })
.filter({ userid })
.limit(100)
.coerceTo('array')
return table.run(query)
},
}
}