1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "tables": [
12 {
13 "name": "accounts",
14 "csv": "id,name\r\n01,Ada\r\n01,Duplicate\r\n02,Lin\r\n",
15 "primaryKey": [
16 "id"
17 ],
18 "requiredColumns": [
19 "name"
20 ]
21 },
22 {
23 "name": "orders",
24 "csv": "id,account_id,note\n10,01,child of duplicate\n11,99,orphan\n12,02,\"accepted, link\"\n13,02,\"multi\nline\"\n",
25 "primaryKey": [
26 "id"
27 ],
28 "requiredColumns": [
29 "note"
30 ]
31 },
32 {
33 "name": "items",
34 "csv": "id,order_id,amount\n100,10,-12.5\n101,12,007\n102,11,3\n",
35 "primaryKey": [
36 "id"
37 ],
38 "requiredColumns": [
39 "amount"
40 ]
41 }
42 ],
43 "foreignKeys": [
44 {
45 "table": "orders",
46 "columns": [
47 "account_id"
48 ],
49 "referencesTable": "accounts",
50 "referencesColumns": [
51 "id"
52 ],
53 "nullable": false
54 },
55 {
56 "table": "items",
57 "columns": [
58 "order_id"
59 ],
60 "referencesTable": "orders",
61 "referencesColumns": [
62 "id"
63 ],
64 "nullable": false
65 }
66 ]
67};
68
69
70const run = await client.actor("bread-kim/csv-foreign-key-import-gate").call(input);
71
72
73console.log('Results from dataset');
74console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
75const { items } = await client.dataset(run.defaultDatasetId).listItems();
76items.forEach((item) => {
77 console.dir(item);
78});
79
80