-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase-memory.js
More file actions
38 lines (31 loc) · 918 Bytes
/
Copy pathdatabase-memory.js
File metadata and controls
38 lines (31 loc) · 918 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
35
36
37
38
import { randomUUID } from "crypto";
export class DatabaseMemory {
#videos = new Map();
list(search) {
//entries retorna um array de array que no indice 0 é o id e no indice 1 é os dados
return Array.from(this.#videos.entries())
.map((videoArr) => {
//pra isso percorremos o array e retornamos em um novo formato
const id = videoArr[0];
const data = videoArr[1];
return { id, ...data };
})
.filter((video) => {
//se tiver uma busca eu retorno o video da busca se nao eu retorno todos
if (search) {
return video.title.includes(search);
}
return true;
});
}
create(video) {
const videoId = randomUUID();
this.#videos.set(videoId, video);
}
update(id, video) {
this.#videos.set(id, video);
}
delete(id) {
this.#videos.delete(id);
}
}