diff options
Diffstat (limited to 'shared/utils/miscs/sql.ts')
-rw-r--r-- | shared/utils/miscs/sql.ts | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/shared/utils/miscs/sql.ts b/shared/utils/miscs/sql.ts index 1ce3d801a..b281471ce 100644 --- a/shared/utils/miscs/sql.ts +++ b/shared/utils/miscs/sql.ts | |||
@@ -48,6 +48,20 @@ function setPlaylistField (serverNumber: number, uuid: string, field: string, va | |||
48 | return seq.query(`UPDATE "videoPlaylist" SET "${field}" = '${value}' WHERE uuid = '${uuid}'`, options) | 48 | return seq.query(`UPDATE "videoPlaylist" SET "${field}" = '${value}' WHERE uuid = '${uuid}'`, options) |
49 | } | 49 | } |
50 | 50 | ||
51 | async function countVideoViewsOf (serverNumber: number, uuid: string) { | ||
52 | const seq = getSequelize(serverNumber) | ||
53 | |||
54 | // tslint:disable | ||
55 | const query = `SELECT SUM("videoView"."views") AS "total" FROM "videoView" INNER JOIN "video" ON "video"."id" = "videoView"."videoId" WHERE "video"."uuid" = '${uuid}'` | ||
56 | |||
57 | const options = { type: Sequelize.QueryTypes.SELECT } | ||
58 | const [ { total } ] = await seq.query(query, options) | ||
59 | |||
60 | if (!total) return 0 | ||
61 | |||
62 | return parseInt(total, 10) | ||
63 | } | ||
64 | |||
51 | async function closeAllSequelize (servers: any[]) { | 65 | async function closeAllSequelize (servers: any[]) { |
52 | for (let i = 1; i <= servers.length; i++) { | 66 | for (let i = 1; i <= servers.length; i++) { |
53 | if (sequelizes[ i ]) { | 67 | if (sequelizes[ i ]) { |
@@ -61,5 +75,6 @@ export { | |||
61 | setVideoField, | 75 | setVideoField, |
62 | setPlaylistField, | 76 | setPlaylistField, |
63 | setActorField, | 77 | setActorField, |
78 | countVideoViewsOf, | ||
64 | closeAllSequelize | 79 | closeAllSequelize |
65 | } | 80 | } |