aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/sql
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-03-03 10:23:44 +0100
committerChocobozzz <me@florianbigard.com>2022-03-03 10:23:44 +0100
commit156c44c8f6522686635089ecff7a358b4145d545 (patch)
tree770d4b8b154ee0942fc7e37ffd697a3b7ec02c71 /server/models/video/sql
parentbf521f51fc561b38d2e1432213a75427f671dda9 (diff)
downloadPeerTube-156c44c8f6522686635089ecff7a358b4145d545.tar.gz
PeerTube-156c44c8f6522686635089ecff7a358b4145d545.tar.zst
PeerTube-156c44c8f6522686635089ecff7a358b4145d545.zip
Refactor a little bit raw sql builders
Diffstat (limited to 'server/models/video/sql')
-rw-r--r--server/models/video/sql/video/shared/abstract-run-query.ts26
-rw-r--r--server/models/video/sql/video/shared/abstract-video-query-builder.ts12
-rw-r--r--server/models/video/sql/video/shared/video-file-query-builder.ts2
-rw-r--r--server/models/video/sql/video/shared/video-model-builder.ts4
-rw-r--r--server/models/video/sql/video/shared/video-table-attributes.ts2
-rw-r--r--server/models/video/sql/video/video-model-get-query-builder.ts2
-rw-r--r--server/models/video/sql/video/videos-id-list-query-builder.ts4
-rw-r--r--server/models/video/sql/video/videos-model-list-query-builder.ts2
8 files changed, 16 insertions, 38 deletions
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 @@
1import { QueryTypes, Sequelize, Transaction } from 'sequelize'
2
3/**
4 *
5 * Abstact builder to run video SQL queries
6 *
7 */
8
9export class AbstractRunQuery {
10 protected sequelize: Sequelize
11
12 protected query: string
13 protected replacements: any = {}
14
15 protected runQuery (options: { transaction?: Transaction, logging?: boolean } = {}) {
16 const queryOptions = {
17 transaction: options.transaction,
18 logging: options.logging,
19 replacements: this.replacements,
20 type: QueryTypes.SELECT as QueryTypes.SELECT,
21 nest: false
22 }
23
24 return this.sequelize.query<any>(this.query, queryOptions)
25 }
26}
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 @@
1import { Sequelize } from 'sequelize'
2import validator from 'validator'
1import { createSafeIn } from '@server/models/utils' 3import { createSafeIn } from '@server/models/utils'
2import { MUserAccountId } from '@server/types/models' 4import { MUserAccountId } from '@server/types/models'
3import { ActorImageType } from '@shared/models' 5import { ActorImageType } from '@shared/models'
4import validator from 'validator' 6import { AbstractRunQuery } from '../../../../shared/abstract-run-query'
5import { AbstractRunQuery } from './abstract-run-query'
6import { VideoTableAttributes } from './video-table-attributes' 7import { VideoTableAttributes } from './video-table-attributes'
7 8
8/** 9/**
@@ -19,8 +20,11 @@ export class AbstractVideoQueryBuilder extends AbstractRunQuery {
19 20
20 protected tables: VideoTableAttributes 21 protected tables: VideoTableAttributes
21 22
22 constructor (protected readonly mode: 'list' | 'get') { 23 constructor (
23 super() 24 protected readonly sequelize: Sequelize,
25 protected readonly mode: 'list' | 'get'
26 ) {
27 super(sequelize)
24 28
25 this.tables = new VideoTableAttributes(this.mode) 29 this.tables = new VideoTableAttributes(this.mode)
26 } 30 }
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 {
12 protected attributes: { [key: string]: string } 12 protected attributes: { [key: string]: string }
13 13
14 constructor (protected readonly sequelize: Sequelize) { 14 constructor (protected readonly sequelize: Sequelize) {
15 super('get') 15 super(sequelize, 'get')
16 } 16 }
17 17
18 queryWebTorrentVideos (options: BuildVideoGetQueryOptions) { 18 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 {
51 private readonly buildOpts = { raw: true, isNewRecord: false } 51 private readonly buildOpts = { raw: true, isNewRecord: false }
52 52
53 constructor ( 53 constructor (
54 readonly mode: 'get' | 'list', 54 private readonly mode: 'get' | 'list',
55 readonly tables: VideoTableAttributes 55 private readonly tables: VideoTableAttributes
56 ) { 56 ) {
57 57
58 } 58 }
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 @@
6 */ 6 */
7export class VideoTableAttributes { 7export class VideoTableAttributes {
8 8
9 constructor (readonly mode: 'get' | 'list') { 9 constructor (private readonly mode: 'get' | 'list') {
10 10
11 } 11 }
12 12
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 {
110 ]) 110 ])
111 111
112 constructor (protected readonly sequelize: Sequelize) { 112 constructor (protected readonly sequelize: Sequelize) {
113 super('get') 113 super(sequelize, 'get')
114 } 114 }
115 115
116 queryVideos (options: BuildVideoGetQueryOptions) { 116 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'
5import { buildDirectionAndField, createSafeIn } from '@server/models/utils' 5import { buildDirectionAndField, createSafeIn } from '@server/models/utils'
6import { MUserAccountId, MUserId } from '@server/types/models' 6import { MUserAccountId, MUserId } from '@server/types/models'
7import { VideoInclude, VideoPrivacy, VideoState } from '@shared/models' 7import { VideoInclude, VideoPrivacy, VideoState } from '@shared/models'
8import { AbstractRunQuery } from './shared/abstract-run-query' 8import { AbstractRunQuery } from '../../../shared/abstract-run-query'
9 9
10/** 10/**
11 * 11 *
@@ -93,7 +93,7 @@ export class VideosIdListQueryBuilder extends AbstractRunQuery {
93 private offset = '' 93 private offset = ''
94 94
95 constructor (protected readonly sequelize: Sequelize) { 95 constructor (protected readonly sequelize: Sequelize) {
96 super() 96 super(sequelize)
97 } 97 }
98 98
99 queryVideoIds (options: BuildVideosListQueryOptions) { 99 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 {
19 private readonly videoModelBuilder: VideoModelBuilder 19 private readonly videoModelBuilder: VideoModelBuilder
20 20
21 constructor (protected readonly sequelize: Sequelize) { 21 constructor (protected readonly sequelize: Sequelize) {
22 super('list') 22 super(sequelize, 'list')
23 23
24 this.videoModelBuilder = new VideoModelBuilder(this.mode, this.tables) 24 this.videoModelBuilder = new VideoModelBuilder(this.mode, this.tables)
25 } 25 }