-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase-postgres.js
More file actions
34 lines (25 loc) · 925 Bytes
/
Copy pathdatabase-postgres.js
File metadata and controls
34 lines (25 loc) · 925 Bytes
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
import { randomUUID } from "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}`
}
}