aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/utils
diff options
context:
space:
mode:
Diffstat (limited to 'shared/utils')
-rw-r--r--shared/utils/miscs/sql.ts22
1 files changed, 20 insertions, 2 deletions
diff --git a/shared/utils/miscs/sql.ts b/shared/utils/miscs/sql.ts
index 027f78131..bb3f63837 100644
--- a/shared/utils/miscs/sql.ts
+++ b/shared/utils/miscs/sql.ts
@@ -1,19 +1,27 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2
3let sequelizes: { [ id: number ]: Sequelize.Sequelize } = {}
4
3function getSequelize (serverNumber: number) { 5function getSequelize (serverNumber: number) {
6 if (sequelizes[serverNumber]) return sequelizes[serverNumber]
7
4 const dbname = 'peertube_test' + serverNumber 8 const dbname = 'peertube_test' + serverNumber
5 const username = 'peertube' 9 const username = 'peertube'
6 const password = 'peertube' 10 const password = 'peertube'
7 const host = 'localhost' 11 const host = 'localhost'
8 const port = 5432 12 const port = 5432
9 13
10 return new Sequelize(dbname, username, password, { 14 const seq = new Sequelize(dbname, username, password, {
11 dialect: 'postgres', 15 dialect: 'postgres',
12 host, 16 host,
13 port, 17 port,
14 operatorsAliases: false, 18 operatorsAliases: false,
15 logging: false 19 logging: false
16 }) 20 })
21
22 sequelizes[serverNumber] = seq
23
24 return seq
17} 25}
18 26
19function setActorField (serverNumber: number, to: string, field: string, value: string) { 27function setActorField (serverNumber: number, to: string, field: string, value: string) {
@@ -32,7 +40,17 @@ function setVideoField (serverNumber: number, uuid: string, field: string, value
32 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)
33} 41}
34 42
43async function closeAllSequelize (servers: any[]) {
44 for (let i = 1; i <= servers.length; i++) {
45 if (sequelizes[ i ]) {
46 await sequelizes[ i ].close()
47 delete sequelizes[ i ]
48 }
49 }
50}
51
35export { 52export {
36 setVideoField, 53 setVideoField,
37 setActorField 54 setActorField,
55 closeAllSequelize
38} 56}