-
Notifications
You must be signed in to change notification settings - Fork 0
/
database-postgres.js
37 lines (26 loc) · 1015 Bytes
/
database-postgres.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { randomUUID } from "node:crypto"
import { sql } from './db.js'
export class DatabasePostgres {
async list(search) {
let videos
if (search) {
videos = await sql`select * from videos where title ILIKE ${'%' + search + '%'}`
} else {
videos = await sql`select * from videos`
}
return videos
}
async create(video) {
const videoId = randomUUID()
const { title, description, duration } = video
await sql`INSERT INTO videos (id, title, description, duration) VALUES (${videoId}, ${title}, ${description}, ${duration})`
}
async update(id, video) {
const {title, description, duration } = video
await sql`UPDATE videos SET title = ${title}, description = ${description}, duration = ${duration} WHERE id = ${id}`
}
async delete(id) {
// const {title, description, duration } = video
await sql`DELETE FROM videos WHERE id = ${id}`
}
}