-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase-postgres.js
35 lines (26 loc) · 963 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
//UUID - Unique Universal ID
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) {
await sql `delete from videos where id = ${id}`
}
}