diff options
author | Chocobozzz <me@florianbigard.com> | 2021-02-26 16:26:27 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-03-03 10:08:08 +0100 |
commit | 74d249bc1346c7cfaac7ee49bebbebcf2a01f82a (patch) | |
tree | d47bd163ae57ed8f15b445296634cc04f4f67b6f /shared/extra-utils/miscs | |
parent | 095e2258043fcff8a79ab082d11edfbd8f13a8e2 (diff) | |
download | PeerTube-74d249bc1346c7cfaac7ee49bebbebcf2a01f82a.tar.gz PeerTube-74d249bc1346c7cfaac7ee49bebbebcf2a01f82a.tar.zst PeerTube-74d249bc1346c7cfaac7ee49bebbebcf2a01f82a.zip |
Add ability to cleanup remote AP interactions
Diffstat (limited to 'shared/extra-utils/miscs')
-rw-r--r-- | shared/extra-utils/miscs/sql.ts | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/shared/extra-utils/miscs/sql.ts b/shared/extra-utils/miscs/sql.ts index e68812e1b..740f0c2d6 100644 --- a/shared/extra-utils/miscs/sql.ts +++ b/shared/extra-utils/miscs/sql.ts | |||
@@ -24,6 +24,25 @@ function getSequelize (internalServerNumber: number) { | |||
24 | return seq | 24 | return seq |
25 | } | 25 | } |
26 | 26 | ||
27 | function deleteAll (internalServerNumber: number, table: string) { | ||
28 | const seq = getSequelize(internalServerNumber) | ||
29 | |||
30 | const options = { type: QueryTypes.DELETE } | ||
31 | |||
32 | return seq.query(`DELETE FROM "${table}"`, options) | ||
33 | } | ||
34 | |||
35 | async function getCount (internalServerNumber: number, table: string) { | ||
36 | const seq = getSequelize(internalServerNumber) | ||
37 | |||
38 | const options = { type: QueryTypes.SELECT as QueryTypes.SELECT } | ||
39 | |||
40 | const [ { total } ] = await seq.query<{ total: string }>(`SELECT COUNT(*) as total FROM "${table}"`, options) | ||
41 | if (total === null) return 0 | ||
42 | |||
43 | return parseInt(total, 10) | ||
44 | } | ||
45 | |||
27 | function setActorField (internalServerNumber: number, to: string, field: string, value: string) { | 46 | function setActorField (internalServerNumber: number, to: string, field: string, value: string) { |
28 | const seq = getSequelize(internalServerNumber) | 47 | const seq = getSequelize(internalServerNumber) |
29 | 48 | ||
@@ -63,6 +82,20 @@ async function countVideoViewsOf (internalServerNumber: number, uuid: string) { | |||
63 | return parseInt(total + '', 10) | 82 | return parseInt(total + '', 10) |
64 | } | 83 | } |
65 | 84 | ||
85 | function selectQuery (internalServerNumber: number, query: string) { | ||
86 | const seq = getSequelize(internalServerNumber) | ||
87 | const options = { type: QueryTypes.SELECT as QueryTypes.SELECT } | ||
88 | |||
89 | return seq.query<any>(query, options) | ||
90 | } | ||
91 | |||
92 | function updateQuery (internalServerNumber: number, query: string) { | ||
93 | const seq = getSequelize(internalServerNumber) | ||
94 | const options = { type: QueryTypes.UPDATE as QueryTypes.UPDATE } | ||
95 | |||
96 | return seq.query(query, options) | ||
97 | } | ||
98 | |||
66 | async function closeAllSequelize (servers: ServerInfo[]) { | 99 | async function closeAllSequelize (servers: ServerInfo[]) { |
67 | for (const server of servers) { | 100 | for (const server of servers) { |
68 | if (sequelizes[server.internalServerNumber]) { | 101 | if (sequelizes[server.internalServerNumber]) { |
@@ -95,6 +128,10 @@ export { | |||
95 | setActorField, | 128 | setActorField, |
96 | countVideoViewsOf, | 129 | countVideoViewsOf, |
97 | setPluginVersion, | 130 | setPluginVersion, |
131 | selectQuery, | ||
132 | deleteAll, | ||
133 | updateQuery, | ||
98 | setActorFollowScores, | 134 | setActorFollowScores, |
99 | closeAllSequelize | 135 | closeAllSequelize, |
136 | getCount | ||
100 | } | 137 | } |