aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-18 11:28:17 +0200
committerChocobozzz <me@florianbigard.com>2019-04-24 16:26:20 +0200
commit1735c825726edaa0af5035cb6cbb0cc0db502c6d (patch)
tree7bbb442f2cb4d7be58a4e08d87f5974403a3047c /shared
parente8bafea35bc930cb8ac5b2d521a188642a1adffe (diff)
downloadPeerTube-1735c825726edaa0af5035cb6cbb0cc0db502c6d.tar.gz
PeerTube-1735c825726edaa0af5035cb6cbb0cc0db502c6d.tar.zst
PeerTube-1735c825726edaa0af5035cb6cbb0cc0db502c6d.zip
Update sequelize
Diffstat (limited to 'shared')
-rw-r--r--shared/extra-utils/miscs/sql.ts17
1 files changed, 9 insertions, 8 deletions
diff --git a/shared/extra-utils/miscs/sql.ts b/shared/extra-utils/miscs/sql.ts
index b281471ce..7aebffc32 100644
--- a/shared/extra-utils/miscs/sql.ts
+++ b/shared/extra-utils/miscs/sql.ts
@@ -1,6 +1,6 @@
1import * as Sequelize from 'sequelize' 1import { QueryTypes, Sequelize } from 'sequelize'
2 2
3let sequelizes: { [ id: number ]: Sequelize.Sequelize } = {} 3let sequelizes: { [ id: number ]: Sequelize } = {}
4 4
5function getSequelize (serverNumber: number) { 5function getSequelize (serverNumber: number) {
6 if (sequelizes[serverNumber]) return sequelizes[serverNumber] 6 if (sequelizes[serverNumber]) return sequelizes[serverNumber]
@@ -27,7 +27,7 @@ function getSequelize (serverNumber: number) {
27function setActorField (serverNumber: number, to: string, field: string, value: string) { 27function setActorField (serverNumber: number, to: string, field: string, value: string) {
28 const seq = getSequelize(serverNumber) 28 const seq = getSequelize(serverNumber)
29 29
30 const options = { type: Sequelize.QueryTypes.UPDATE } 30 const options = { type: QueryTypes.UPDATE }
31 31
32 return seq.query(`UPDATE actor SET "${field}" = '${value}' WHERE url = '${to}'`, options) 32 return seq.query(`UPDATE actor SET "${field}" = '${value}' WHERE url = '${to}'`, options)
33} 33}
@@ -35,7 +35,7 @@ function setActorField (serverNumber: number, to: string, field: string, value:
35function setVideoField (serverNumber: number, uuid: string, field: string, value: string) { 35function setVideoField (serverNumber: number, uuid: string, field: string, value: string) {
36 const seq = getSequelize(serverNumber) 36 const seq = getSequelize(serverNumber)
37 37
38 const options = { type: Sequelize.QueryTypes.UPDATE } 38 const options = { type: QueryTypes.UPDATE }
39 39
40 return seq.query(`UPDATE video SET "${field}" = '${value}' WHERE uuid = '${uuid}'`, options) 40 return seq.query(`UPDATE video SET "${field}" = '${value}' WHERE uuid = '${uuid}'`, options)
41} 41}
@@ -43,7 +43,7 @@ function setVideoField (serverNumber: number, uuid: string, field: string, value
43function setPlaylistField (serverNumber: number, uuid: string, field: string, value: string) { 43function setPlaylistField (serverNumber: number, uuid: string, field: string, value: string) {
44 const seq = getSequelize(serverNumber) 44 const seq = getSequelize(serverNumber)
45 45
46 const options = { type: Sequelize.QueryTypes.UPDATE } 46 const options = { type: QueryTypes.UPDATE }
47 47
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}
@@ -54,12 +54,13 @@ async function countVideoViewsOf (serverNumber: number, uuid: string) {
54 // tslint:disable 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}'` 55 const query = `SELECT SUM("videoView"."views") AS "total" FROM "videoView" INNER JOIN "video" ON "video"."id" = "videoView"."videoId" WHERE "video"."uuid" = '${uuid}'`
56 56
57 const options = { type: Sequelize.QueryTypes.SELECT } 57 const options = { type: QueryTypes.SELECT as QueryTypes.SELECT }
58 const [ { total } ] = await seq.query(query, options) 58 const [ { total } ] = await seq.query<{ total: number }>(query, options)
59 59
60 if (!total) return 0 60 if (!total) return 0
61 61
62 return parseInt(total, 10) 62 // FIXME: check if we really need parseInt
63 return parseInt(total + '', 10)
63} 64}
64 65
65async function closeAllSequelize (servers: any[]) { 66async function closeAllSequelize (servers: any[]) {