diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-03 10:23:44 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-03-03 10:23:44 +0100 |
commit | 156c44c8f6522686635089ecff7a358b4145d545 (patch) | |
tree | 770d4b8b154ee0942fc7e37ffd697a3b7ec02c71 /server/models/shared | |
parent | bf521f51fc561b38d2e1432213a75427f671dda9 (diff) | |
download | PeerTube-156c44c8f6522686635089ecff7a358b4145d545.tar.gz PeerTube-156c44c8f6522686635089ecff7a358b4145d545.tar.zst PeerTube-156c44c8f6522686635089ecff7a358b4145d545.zip |
Refactor a little bit raw sql builders
Diffstat (limited to 'server/models/shared')
-rw-r--r-- | server/models/shared/abstract-run-query.ts | 28 | ||||
-rw-r--r-- | server/models/shared/index.ts | 1 |
2 files changed, 29 insertions, 0 deletions
diff --git a/server/models/shared/abstract-run-query.ts b/server/models/shared/abstract-run-query.ts new file mode 100644 index 000000000..c39b7bcfe --- /dev/null +++ b/server/models/shared/abstract-run-query.ts | |||
@@ -0,0 +1,28 @@ | |||
1 | import { QueryTypes, Sequelize, Transaction } from 'sequelize' | ||
2 | |||
3 | /** | ||
4 | * | ||
5 | * Abstact builder to run video SQL queries | ||
6 | * | ||
7 | */ | ||
8 | |||
9 | export class AbstractRunQuery { | ||
10 | protected query: string | ||
11 | protected replacements: any = {} | ||
12 | |||
13 | constructor (protected readonly sequelize: Sequelize) { | ||
14 | |||
15 | } | ||
16 | |||
17 | protected runQuery (options: { nest?: boolean, transaction?: Transaction, logging?: boolean } = {}) { | ||
18 | const queryOptions = { | ||
19 | transaction: options.transaction, | ||
20 | logging: options.logging, | ||
21 | replacements: this.replacements, | ||
22 | type: QueryTypes.SELECT as QueryTypes.SELECT, | ||
23 | nest: options.nest ?? false | ||
24 | } | ||
25 | |||
26 | return this.sequelize.query<any>(this.query, queryOptions) | ||
27 | } | ||
28 | } | ||
diff --git a/server/models/shared/index.ts b/server/models/shared/index.ts index 802404555..04528929c 100644 --- a/server/models/shared/index.ts +++ b/server/models/shared/index.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | export * from './abstract-run-query' | ||
1 | export * from './model-builder' | 2 | export * from './model-builder' |
2 | export * from './query' | 3 | export * from './query' |
3 | export * from './update' | 4 | export * from './update' |