-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodifiers.js
94 lines (84 loc) · 1.9 KB
/
modifiers.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const links = 'links'
const keys = 'keys'
const authors = 'authors'
const messages_raw = 'messages_raw'
const messages = 'messages'
const keyId = `${messages}.key_id`
const key = `${messages}.key`
const messageesAuthorId = `${messages}.author_id`
const messageesAuthor = `${messages}.author`
const messageType = `${messages}.content_type`
const messageRootId = `${messages}.root_id`
const messageRoot = `${messages}.root`
const messageFork = `${messages}.fork`
const isDecrypted = `${messages}.is_decrypted`
// Get tip of a feed
// Get all replies to a message
//
module.exports.modifiers = {
whereMessageType,
whereMessageIsNotType,
whereMessageIsPrivate,
whereMessageIsNotPrivate,
joinLinksFrom,
joinLinksTo,
backLinksReferences
}
module.exports.strings = {
messages,
links,
keys
}
function whereMessageType (query, typeString) {
query.where(
messageType, typeString
)
}
function whereMessageIsNotType (query, typeString) {
query.whereNot(
messageType, typeString
)
}
function whereMessageIsNotRoot (query, id) {
query.whereNot(
messageRoot,
id
)
}
function whereMessageIsNotFork (query, id) {
query.whereNot(
messageFork,
id
)
}
function whereMessageIsPrivate (query) {
query.where(
isDecrypted, 1
)
}
function whereMessageIsNotPrivate (query) {
query.whereNot(
isDecrypted, 1
)
}
function joinLinksFrom (query) {
query.join(links, 'links.link_from_key', key)
}
function joinMessagesOnLinksFrom (query) {
query.join(messages, 'links.link_from_key', key)
}
function joinLinksTo (query) {
query.join(links, 'links.link_to_key', key)
}
function backLinksReferences (query, id, knex) {
query
.modify(joinMessagesOnLinksFrom)
.modify(whereMessageIsNotRoot, id)
.modify(whereMessageIsNotType, 'about')
.modify(whereMessageIsNotType, 'vote')
.modify(whereMessageIsNotType, 'tag')
.where(
'links.link_to_key',
id
)
}