-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport.ts
40 lines (36 loc) · 935 Bytes
/
import.ts
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
import faunadb from "faunadb";
import fs from "fs";
const q = faunadb.query;
let client = new faunadb.Client({
secret: "fnAFVnqDsmAAze1MxTl8rNVNEtXnxoN9cZGCmc71",
});
let counter = 0;
const importFile = async (file: string) => {
const data = fs.readFileSync(file, "utf8");
const tasks = JSON.parse(data);
for (const task of tasks) {
const createP = await client.query(
q.Create(q.Collection("Task"), {
data: {
taskNumber: counter,
title: task.name,
description: task.notes,
assignee: task?.assignee?.name,
project: task.projects[0].name,
},
})
);
counter++;
console.log(createP);
}
};
(async () => {
const files = fs.readdirSync("data");
for (const file of files) {
if (file.endsWith(".json")) {
console.log("import file", file);
await importFile("data/" + file);
}
}
console.log("all done");
})();