Remove sequelize deprecated operators

This commit is contained in:
Chocobozzz 2017-10-26 16:59:02 +02:00
parent a265f7f30f
commit c296250511
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
9 changed files with 20 additions and 17 deletions

View File

@ -131,4 +131,3 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
this.form.patchValue(this.video.toJSON()) this.form.patchValue(this.video.toJSON())
} }
} }

View File

@ -64,6 +64,7 @@ const sequelize = new Sequelize(dbname, username, password, {
port: CONFIG.DATABASE.PORT, port: CONFIG.DATABASE.PORT,
benchmark: isTestInstance(), benchmark: isTestInstance(),
isolationLevel: Sequelize.Transaction.ISOLATION_LEVELS.SERIALIZABLE, isolationLevel: Sequelize.Transaction.ISOLATION_LEVELS.SERIALIZABLE,
operatorsAliases: false,
logging: (message: string, benchmark: number) => { logging: (message: string, benchmark: number) => {
let newMessage = message let newMessage = message

View File

@ -130,7 +130,7 @@ incrementScores = function (ids: number[], value: number) {
const options = { const options = {
where: { where: {
id: { id: {
$in: ids [Sequelize.Op.in]: ids
} }
}, },
// In this case score is a literal and not an integer so we do not validate it // In this case score is a literal and not an integer so we do not validate it
@ -178,6 +178,7 @@ listRandomPodIdsWithRequest = function (limit: number, tableWithPods: string, ta
let start = Math.floor(Math.random() * count) - limit let start = Math.floor(Math.random() * count) - limit
if (start < 0) start = 0 if (start < 0) start = 0
const subQuery = `(SELECT DISTINCT "${tableWithPods}"."podId" FROM "${tableWithPods}" ${tableWithPodsJoins})`
const query = { const query = {
attributes: [ 'id' ], attributes: [ 'id' ],
order: [ order: [
@ -187,7 +188,7 @@ listRandomPodIdsWithRequest = function (limit: number, tableWithPods: string, ta
limit: limit, limit: limit,
where: { where: {
id: { id: {
$in: Sequelize.literal(`(SELECT DISTINCT "${tableWithPods}"."podId" FROM "${tableWithPods}" ${tableWithPodsJoins})`) [Sequelize.Op.in]: Sequelize.literal(subQuery)
} }
} }
} }
@ -201,7 +202,9 @@ listRandomPodIdsWithRequest = function (limit: number, tableWithPods: string, ta
listBadPods = function () { listBadPods = function () {
const query = { const query = {
where: { where: {
score: { $lte: 0 } score: {
[Sequelize.Op.lte]: 0
}
} }
} }

View File

@ -41,7 +41,7 @@ removeByRequestIdsAndPod = function (requestsIds: number[], podId: number) {
const query = { const query = {
where: { where: {
requestId: { requestId: {
$in: requestsIds [Sequelize.Op.in]: requestsIds
}, },
podId: podId podId: podId
} }

View File

@ -111,7 +111,7 @@ listWithLimitAndRandom = function (limitPods: number, limitRequestsPerPod: numbe
model: RequestVideoEvent['sequelize'].models.Pod, model: RequestVideoEvent['sequelize'].models.Pod,
where: { where: {
id: { id: {
$in: podIds [Sequelize.Op.in]: podIds
} }
} }
} }
@ -135,7 +135,7 @@ removeByRequestIdsAndPod = function (ids: number[], podId: number) {
const query = { const query = {
where: { where: {
id: { id: {
$in: ids [Sequelize.Op.in]: ids
} }
}, },
include: [ include: [

View File

@ -101,7 +101,7 @@ listWithLimitAndRandom = function (limitPods: number, limitRequestsPerPod: numbe
model: RequestVideoQadu['sequelize'].models.Pod, model: RequestVideoQadu['sequelize'].models.Pod,
where: { where: {
id: { id: {
$in: podIds [Sequelize.Op.in]: podIds
} }
} }
}, },
@ -122,7 +122,7 @@ removeByRequestIdsAndPod = function (ids: number[], podId: number) {
const query = { const query = {
where: { where: {
id: { id: {
$in: ids [Sequelize.Op.in]: ids
}, },
podId podId
} }

View File

@ -88,7 +88,7 @@ listWithLimitAndRandom = function (limitPods: number, limitRequestsPerPod: numbe
model: Request['sequelize'].models.Pod, model: Request['sequelize'].models.Pod,
where: { where: {
id: { id: {
$in: podIds [Sequelize.Op.in]: podIds
} }
} }
} }
@ -112,7 +112,7 @@ removeWithEmptyTo = function () {
const query = { const query = {
where: { where: {
id: { id: {
$notIn: [ [Sequelize.Op.notIn]: [
Sequelize.literal('SELECT "requestId" FROM "RequestToPods"') Sequelize.literal('SELECT "requestId" FROM "RequestToPods"')
] ]
} }

View File

@ -271,7 +271,7 @@ loadByUsernameOrEmail = function (username: string, email: string) {
const query = { const query = {
include: [ { model: User['sequelize'].models.Author, required: true } ], include: [ { model: User['sequelize'].models.Author, required: true } ],
where: { where: {
$or: [ { username }, { email } ] [Sequelize.Op.or]: [ { username }, { email } ]
} }
} }

View File

@ -1012,7 +1012,7 @@ searchAndPopulateAuthorAndPodAndTags = function (value: string, field: string, s
} }
} else if (field === 'tags') { } else if (field === 'tags') {
const escapedValue = Video['sequelize'].escape('%' + value + '%') const escapedValue = Video['sequelize'].escape('%' + value + '%')
query.where['id'].$in = Video['sequelize'].literal( query.where['id'][Sequelize.Op.in] = Video['sequelize'].literal(
`(SELECT "VideoTags"."videoId" `(SELECT "VideoTags"."videoId"
FROM "Tags" FROM "Tags"
INNER JOIN "VideoTags" ON "Tags"."id" = "VideoTags"."tagId" INNER JOIN "VideoTags" ON "Tags"."id" = "VideoTags"."tagId"
@ -1023,19 +1023,19 @@ searchAndPopulateAuthorAndPodAndTags = function (value: string, field: string, s
// FIXME: Include our pod? (not stored in the database) // FIXME: Include our pod? (not stored in the database)
podInclude.where = { podInclude.where = {
host: { host: {
$iLike: '%' + value + '%' [Sequelize.Op.iLike]: '%' + value + '%'
} }
} }
podInclude.required = true podInclude.required = true
} else if (field === 'author') { } else if (field === 'author') {
authorInclude.where = { authorInclude.where = {
name: { name: {
$iLike: '%' + value + '%' [Sequelize.Op.iLike]: '%' + value + '%'
} }
} }
} else { } else {
query.where[field] = { query.where[field] = {
$iLike: '%' + value + '%' [Sequelize.Op.iLike]: '%' + value + '%'
} }
} }
@ -1056,7 +1056,7 @@ searchAndPopulateAuthorAndPodAndTags = function (value: string, field: string, s
function createBaseVideosWhere () { function createBaseVideosWhere () {
return { return {
id: { id: {
$notIn: Video['sequelize'].literal( [Sequelize.Op.notIn]: Video['sequelize'].literal(
'(SELECT "BlacklistedVideos"."videoId" FROM "BlacklistedVideos")' '(SELECT "BlacklistedVideos"."videoId" FROM "BlacklistedVideos")'
) )
} }