2018-10-23 04:38:48 -05:00
|
|
|
import * as Sequelize from 'sequelize'
|
|
|
|
|
2019-02-21 08:44:12 -06:00
|
|
|
let sequelizes: { [ id: number ]: Sequelize.Sequelize } = {}
|
|
|
|
|
2018-10-23 04:38:48 -05:00
|
|
|
function getSequelize (serverNumber: number) {
|
2019-02-21 08:44:12 -06:00
|
|
|
if (sequelizes[serverNumber]) return sequelizes[serverNumber]
|
|
|
|
|
2018-10-23 04:38:48 -05:00
|
|
|
const dbname = 'peertube_test' + serverNumber
|
|
|
|
const username = 'peertube'
|
|
|
|
const password = 'peertube'
|
|
|
|
const host = 'localhost'
|
|
|
|
const port = 5432
|
|
|
|
|
2019-02-21 08:44:12 -06:00
|
|
|
const seq = new Sequelize(dbname, username, password, {
|
2018-10-23 04:38:48 -05:00
|
|
|
dialect: 'postgres',
|
|
|
|
host,
|
|
|
|
port,
|
|
|
|
operatorsAliases: false,
|
|
|
|
logging: false
|
|
|
|
})
|
2019-02-21 08:44:12 -06:00
|
|
|
|
|
|
|
sequelizes[serverNumber] = seq
|
|
|
|
|
|
|
|
return seq
|
2018-10-23 04:38:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function setActorField (serverNumber: number, to: string, field: string, value: string) {
|
|
|
|
const seq = getSequelize(serverNumber)
|
|
|
|
|
|
|
|
const options = { type: Sequelize.QueryTypes.UPDATE }
|
|
|
|
|
|
|
|
return seq.query(`UPDATE actor SET "${field}" = '${value}' WHERE url = '${to}'`, options)
|
|
|
|
}
|
|
|
|
|
2018-11-14 09:32:12 -06:00
|
|
|
function setVideoField (serverNumber: number, uuid: string, field: string, value: string) {
|
|
|
|
const seq = getSequelize(serverNumber)
|
|
|
|
|
|
|
|
const options = { type: Sequelize.QueryTypes.UPDATE }
|
|
|
|
|
|
|
|
return seq.query(`UPDATE video SET "${field}" = '${value}' WHERE uuid = '${uuid}'`, options)
|
|
|
|
}
|
|
|
|
|
2019-02-21 08:44:12 -06:00
|
|
|
async function closeAllSequelize (servers: any[]) {
|
|
|
|
for (let i = 1; i <= servers.length; i++) {
|
|
|
|
if (sequelizes[ i ]) {
|
|
|
|
await sequelizes[ i ].close()
|
|
|
|
delete sequelizes[ i ]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-23 04:38:48 -05:00
|
|
|
export {
|
2018-11-14 09:32:12 -06:00
|
|
|
setVideoField,
|
2019-02-21 08:44:12 -06:00
|
|
|
setActorField,
|
|
|
|
closeAllSequelize
|
2018-10-23 04:38:48 -05:00
|
|
|
}
|