diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-28 10:32:40 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-28 10:32:40 +0200 |
commit | fa47956ecf51a6d5d10aeb25d2e4db3da90c7d58 (patch) | |
tree | bd626648077f84fb4628af3a37acf260597fa0ef /server/models/shared | |
parent | f68d1cb6ac4aa4fb563b9eeb831fccffee260b2f (diff) | |
download | PeerTube-fa47956ecf51a6d5d10aeb25d2e4db3da90c7d58.tar.gz PeerTube-fa47956ecf51a6d5d10aeb25d2e4db3da90c7d58.tar.zst PeerTube-fa47956ecf51a6d5d10aeb25d2e4db3da90c7d58.zip |
Filter host for channels and playlists search
Diffstat (limited to 'server/models/shared')
-rw-r--r-- | server/models/shared/index.ts | 2 | ||||
-rw-r--r-- | server/models/shared/query.ts | 17 | ||||
-rw-r--r-- | server/models/shared/update.ts | 18 |
3 files changed, 37 insertions, 0 deletions
diff --git a/server/models/shared/index.ts b/server/models/shared/index.ts new file mode 100644 index 000000000..5b97510e0 --- /dev/null +++ b/server/models/shared/index.ts | |||
@@ -0,0 +1,2 @@ | |||
1 | export * from './query' | ||
2 | export * from './update' | ||
diff --git a/server/models/shared/query.ts b/server/models/shared/query.ts new file mode 100644 index 000000000..036cc13c6 --- /dev/null +++ b/server/models/shared/query.ts | |||
@@ -0,0 +1,17 @@ | |||
1 | import { BindOrReplacements, QueryTypes } from 'sequelize' | ||
2 | import { sequelizeTypescript } from '@server/initializers/database' | ||
3 | |||
4 | function doesExist (query: string, bind?: BindOrReplacements) { | ||
5 | const options = { | ||
6 | type: QueryTypes.SELECT as QueryTypes.SELECT, | ||
7 | bind, | ||
8 | raw: true | ||
9 | } | ||
10 | |||
11 | return sequelizeTypescript.query(query, options) | ||
12 | .then(results => results.length === 1) | ||
13 | } | ||
14 | |||
15 | export { | ||
16 | doesExist | ||
17 | } | ||
diff --git a/server/models/shared/update.ts b/server/models/shared/update.ts new file mode 100644 index 000000000..d338211e3 --- /dev/null +++ b/server/models/shared/update.ts | |||
@@ -0,0 +1,18 @@ | |||
1 | import { QueryTypes, Transaction } from 'sequelize' | ||
2 | import { sequelizeTypescript } from '@server/initializers/database' | ||
3 | |||
4 | // Sequelize always skip the update if we only update updatedAt field | ||
5 | function setAsUpdated (table: string, id: number, transaction?: Transaction) { | ||
6 | return sequelizeTypescript.query( | ||
7 | `UPDATE "${table}" SET "updatedAt" = :updatedAt WHERE id = :id`, | ||
8 | { | ||
9 | replacements: { table, id, updatedAt: new Date() }, | ||
10 | type: QueryTypes.UPDATE, | ||
11 | transaction | ||
12 | } | ||
13 | ) | ||
14 | } | ||
15 | |||
16 | export { | ||
17 | setAsUpdated | ||
18 | } | ||