You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: getting_started/javascript-client/lesson_2.md
+19-19Lines changed: 19 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -1,42 +1,42 @@
1
-
# Lesson 2 - Importing data from CSV using Javascript script
1
+
# Lesson 2 - Importing data from CSV using JavaScript script
2
2
3
-
## Creating the Javascript script
3
+
## Creating the JavaScript script
4
4
5
-
Let's start a new `.js` file [insert_data.js](insert_data.js). You can copy and paste the one we have in this repo or build one yourself. We will explain the one we have so you have an idea what it does.
5
+
Let's start a new `.js` file called [insert_data.js](insert_data.js). You can copy and paste the one we have in this repo or build one yourself. We will explain the one we have so you know what it does.
6
6
7
-
In the first half of the script, we have to manage and import the data form CSV. In Node.JS there is the [`fast-csv` package](https://www.npmjs.com/package/fast-csv)which can aid reading of CSV files.
7
+
In the first half of the script we have to manage and import the data from the CSV. In Node.JS there is the [`fast-csv` package](https://www.npmjs.com/package/fast-csv)that helps reading of CSV files.
8
8
9
-
First we will install the package:
9
+
First, install the package:
10
10
11
11
```bash
12
12
npm i fast-csv
13
13
```
14
14
15
-
Now we will import it as well as some other packages:
15
+
The script will import this package with some others:
16
16
17
17
```javascript
18
18
constfs=require("fs");
19
19
constpath=require("path");
20
20
constcsv=require("fast-csv");
21
21
```
22
22
23
-
Also we need to import `WOQLClient` which is the client that communitcate with the TerminusDB/TerminusCMS:
23
+
It will also import `WOQLClient` which is the client that communitcates with the TerminusDB/TerminusCMS:
At the top of the script, we prepare a few empty objects and list to hold the data, we use objects cause the keys can be the `Employees id` for easy mapping:
29
+
At the top of the script, we prepare a few empty objects and list to hold the data, we use objects as the keys can be the `Employees id` for easy mapping:
30
30
31
31
```javascript
32
32
constcontact_numbers= {};
33
33
constaddresses= {};
34
34
constemployees= [];
35
35
```
36
36
37
-
The goal is to populate the `employees` list with the `Employee` objects. To help, we also need `contact_numbers` to hold the contact numbers while reading the `Contact.csv`. The rest of the information in `Contact.csv` will be used to construct `Address` objects and stored in `addresses`. We store the id at first and make the linking later cause the manager of that employee may have not been "created" yet.
37
+
The goal is to populate the `employees` list with the `Employee` objects. To help, we also need `contact_numbers` to hold the contact numbers while reading the `Contact.csv`. The rest of the information in `Contact.csv` will be used to construct `Address` objects and stored in `addresses`. We store the id at first and make the linking later because the manager of that employee may have not been "created" yet.
38
38
39
-
Then we go head and read the CSVs and do the corresponding data managing:
39
+
Then we go ahead and read the CSVs and do the corresponding data managing:
Now, the `employees` list should be populated with the `Employee` objects that is ready to be insert into the database.
106
+
The `employees` list should now be populated with the `Employee` objects, ready to be inserted into the database.
107
107
108
-
## Using the Javascript client
108
+
## Using the TerminusDB JavaScript Client
109
109
110
-
The next step is the insert all `Employees` into the database. But before, we need to create a client with our cloud endpoint:
110
+
The script inserts all `Employees` into the database using the TerminusDB JavaScript Client. To do this, we need to create a client with our cloud endpoint:
111
111
112
112
```javascript
113
113
// TODO: Change teamname and username
@@ -123,9 +123,9 @@ const client = new TerminusClient.WOQLClient(
If you are using TerminusCMS, you can find the information of your endpoint, team, and API token from the [TerminusCMS dashboard](https://dashboard.terminusdb.com/) under profile.
126
+
If you are using TerminusCMS, you can find the your endpoint, team, and API token in the [TerminusCMS dashboard](https://dashboard.terminusdb.com/) under profile.
127
127
128
-
Now we are all ready, the last thing to do is to insert the documents:
0 commit comments