From 156c44c8f6522686635089ecff7a358b4145d545 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 3 Mar 2022 10:23:44 +0100 Subject: Refactor a little bit raw sql builders --- .../video/sql/video/shared/abstract-run-query.ts | 26 ---------------------- .../video/shared/abstract-video-query-builder.ts | 12 ++++++---- .../sql/video/shared/video-file-query-builder.ts | 2 +- .../video/sql/video/shared/video-model-builder.ts | 4 ++-- .../sql/video/shared/video-table-attributes.ts | 2 +- .../sql/video/video-model-get-query-builder.ts | 2 +- .../sql/video/videos-id-list-query-builder.ts | 4 ++-- .../sql/video/videos-model-list-query-builder.ts | 2 +- 8 files changed, 16 insertions(+), 38 deletions(-) delete mode 100644 server/models/video/sql/video/shared/abstract-run-query.ts (limited to 'server/models/video') diff --git a/server/models/video/sql/video/shared/abstract-run-query.ts b/server/models/video/sql/video/shared/abstract-run-query.ts deleted file mode 100644 index 8e7a7642d..000000000 --- a/server/models/video/sql/video/shared/abstract-run-query.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { QueryTypes, Sequelize, Transaction } from 'sequelize' - -/** - * - * Abstact builder to run video SQL queries - * - */ - -export class AbstractRunQuery { - protected sequelize: Sequelize - - protected query: string - protected replacements: any = {} - - protected runQuery (options: { transaction?: Transaction, logging?: boolean } = {}) { - const queryOptions = { - transaction: options.transaction, - logging: options.logging, - replacements: this.replacements, - type: QueryTypes.SELECT as QueryTypes.SELECT, - nest: false - } - - return this.sequelize.query(this.query, queryOptions) - } -} diff --git a/server/models/video/sql/video/shared/abstract-video-query-builder.ts b/server/models/video/sql/video/shared/abstract-video-query-builder.ts index 490e5e6e0..b79d20ade 100644 --- a/server/models/video/sql/video/shared/abstract-video-query-builder.ts +++ b/server/models/video/sql/video/shared/abstract-video-query-builder.ts @@ -1,8 +1,9 @@ +import { Sequelize } from 'sequelize' +import validator from 'validator' import { createSafeIn } from '@server/models/utils' import { MUserAccountId } from '@server/types/models' import { ActorImageType } from '@shared/models' -import validator from 'validator' -import { AbstractRunQuery } from './abstract-run-query' +import { AbstractRunQuery } from '../../../../shared/abstract-run-query' import { VideoTableAttributes } from './video-table-attributes' /** @@ -19,8 +20,11 @@ export class AbstractVideoQueryBuilder extends AbstractRunQuery { protected tables: VideoTableAttributes - constructor (protected readonly mode: 'list' | 'get') { - super() + constructor ( + protected readonly sequelize: Sequelize, + protected readonly mode: 'list' | 'get' + ) { + super(sequelize) this.tables = new VideoTableAttributes(this.mode) } diff --git a/server/models/video/sql/video/shared/video-file-query-builder.ts b/server/models/video/sql/video/shared/video-file-query-builder.ts index 3eb3dc07d..50c12f627 100644 --- a/server/models/video/sql/video/shared/video-file-query-builder.ts +++ b/server/models/video/sql/video/shared/video-file-query-builder.ts @@ -12,7 +12,7 @@ export class VideoFileQueryBuilder extends AbstractVideoQueryBuilder { protected attributes: { [key: string]: string } constructor (protected readonly sequelize: Sequelize) { - super('get') + super(sequelize, 'get') } queryWebTorrentVideos (options: BuildVideoGetQueryOptions) { diff --git a/server/models/video/sql/video/shared/video-model-builder.ts b/server/models/video/sql/video/shared/video-model-builder.ts index 166ff9d31..0a2beb7db 100644 --- a/server/models/video/sql/video/shared/video-model-builder.ts +++ b/server/models/video/sql/video/shared/video-model-builder.ts @@ -51,8 +51,8 @@ export class VideoModelBuilder { private readonly buildOpts = { raw: true, isNewRecord: false } constructor ( - readonly mode: 'get' | 'list', - readonly tables: VideoTableAttributes + private readonly mode: 'get' | 'list', + private readonly tables: VideoTableAttributes ) { } diff --git a/server/models/video/sql/video/shared/video-table-attributes.ts b/server/models/video/sql/video/shared/video-table-attributes.ts index df2ed3fb0..f4d9e99fd 100644 --- a/server/models/video/sql/video/shared/video-table-attributes.ts +++ b/server/models/video/sql/video/shared/video-table-attributes.ts @@ -6,7 +6,7 @@ */ export class VideoTableAttributes { - constructor (readonly mode: 'get' | 'list') { + constructor (private readonly mode: 'get' | 'list') { } diff --git a/server/models/video/sql/video/video-model-get-query-builder.ts b/server/models/video/sql/video/video-model-get-query-builder.ts index a65c96097..b0879c9ac 100644 --- a/server/models/video/sql/video/video-model-get-query-builder.ts +++ b/server/models/video/sql/video/video-model-get-query-builder.ts @@ -110,7 +110,7 @@ export class VideosModelGetQuerySubBuilder extends AbstractVideoQueryBuilder { ]) constructor (protected readonly sequelize: Sequelize) { - super('get') + super(sequelize, 'get') } queryVideos (options: BuildVideoGetQueryOptions) { diff --git a/server/models/video/sql/video/videos-id-list-query-builder.ts b/server/models/video/sql/video/videos-id-list-query-builder.ts index 098e15359..19aff631d 100644 --- a/server/models/video/sql/video/videos-id-list-query-builder.ts +++ b/server/models/video/sql/video/videos-id-list-query-builder.ts @@ -5,7 +5,7 @@ import { WEBSERVER } from '@server/initializers/constants' import { buildDirectionAndField, createSafeIn } from '@server/models/utils' import { MUserAccountId, MUserId } from '@server/types/models' import { VideoInclude, VideoPrivacy, VideoState } from '@shared/models' -import { AbstractRunQuery } from './shared/abstract-run-query' +import { AbstractRunQuery } from '../../../shared/abstract-run-query' /** * @@ -93,7 +93,7 @@ export class VideosIdListQueryBuilder extends AbstractRunQuery { private offset = '' constructor (protected readonly sequelize: Sequelize) { - super() + super(sequelize) } queryVideoIds (options: BuildVideosListQueryOptions) { diff --git a/server/models/video/sql/video/videos-model-list-query-builder.ts b/server/models/video/sql/video/videos-model-list-query-builder.ts index b15b29ec3..2a4afc389 100644 --- a/server/models/video/sql/video/videos-model-list-query-builder.ts +++ b/server/models/video/sql/video/videos-model-list-query-builder.ts @@ -19,7 +19,7 @@ export class VideosModelListQueryBuilder extends AbstractVideoQueryBuilder { private readonly videoModelBuilder: VideoModelBuilder constructor (protected readonly sequelize: Sequelize) { - super('list') + super(sequelize, 'list') this.videoModelBuilder = new VideoModelBuilder(this.mode, this.tables) } -- cgit v1.2.3