-
Notifications
You must be signed in to change notification settings - Fork 5
/
1.2-seed-movies.js
61 lines (53 loc) · 1.18 KB
/
1.2-seed-movies.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { ddb, log, LineParser, LineReader } from "./helpers/index.js";
const lineParser = new LineParser();
function seed() {
let counter = 0;
let seedCounter = 0;
LineReader("title.basics", async (line) => {
if (counter++ === 0) {
lineParser.setColumn(line);
return;
}
const { tconst, originalTitle, runtimeMinutes, genres, startYear } =
lineParser.parse(line);
const params = {
TableName: "Movies",
Item: {
tconst: {
S: tconst,
},
sk: {
S: "MOVIE",
},
originalTitle: {
S: originalTitle,
},
startYear: {
N: startYear,
},
runtimeMinutes: {
N: runtimeMinutes,
},
genres: {
SS: genres.split(","),
},
},
ReturnConsumedCapacity: "TOTAL",
};
if (genres === "\\N") {
delete params.Item.genres;
}
try {
log(counter, seedCounter);
await ddb
.putItem(params)
.promise()
.then(() => log(counter, ++seedCounter));
} catch (error) {
console.log(error);
console.log(params);
process.exit(1);
}
});
}
seed();