Skip to content

Commit

Permalink
Merge pull request #134 from skyflowapi/SK-1370-readme-changelog-samp…
Browse files Browse the repository at this point in the history
…les-for-continue-on-error-in-batch-insert

SK-1370 README, CHANGELOG and Samples
  • Loading branch information
skyflow-vivek authored Jan 12, 2024
2 parents 10997d6 + 365d255 commit 0232f95
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to this project will be documented in this file.

## [1.13.0] - 2024-01-12
### Added
- Removed get call from batch Insert.
- Continue on error support for batch Insert.

## [1.12.0] - 2023-10-20
### Added
- `tokens` option in `get` interface.
Expand Down
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,73 @@ response.then(
});
```

Insert call [example](https://github.com/skyflowapi/skyflow-node/blob/master/samples/vault-api/InsertWithContinueOnError.ts) with contiueOnError support:

```javascript
const response = client.insert({
records: [
{
fields: {
expiry_date: '12/2026',
card_number: '411111111111111',
namee: 'john doe',
},
table: 'cards',
},
{
fields: {
expiry_date: '12/2027',
card_number: '411111111111111',
name: 'jane doe',
},
table: 'cards',
}
],
},
{
tokens: true,
continueOnError: true,
});

response.then(
(res) => {
console.log(JSON.stringify(res));
},
(err) => {
console.log(JSON.stringify(err));
}
).catch((err) => {
console.log(JSON.stringify(err));
});
```

Sample Response:
```json
{
"records": [
{
"table": "cards",
"fields": {
"skyflow_id": "16419435-aa63-4823-aae7-19c6a2d6a19f",
"card_number": "f3907186-e7e2-466f-91e5-48e12c2bcbc1",
"expiry_date": "1989cb56-63da-4482-a2df-1f74cd0dd1a5",
"name": "245d3a0f-a2d3-443b-8a20-8c17de86e186",
},
"request_index": 1,
}
],
"errors": [
{
"error": {
"code":400,
"description":"Invalid field present in JSON namee - requestId: 87fb2e32-6287-4e61-8304-9268df12bfe8",
"request_index": 0,
}
}
]
}
```

#### Detokenize
In order to retrieve data from your vault using tokens that you have previously generated for that data, you can use the `detokenize(records)` method. The first parameter must have a records key that takes an array of tokens to be fetched from the vault, as shown below.

Expand Down
2 changes: 1 addition & 1 deletion samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"skyflow-node": "^1.11.0"
"skyflow-node": "^1.13.0"
}
}
72 changes: 72 additions & 0 deletions samples/vault-api/InsertWithContinueOnError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Copyright (c) 2024 Skyflow, Inc.
*/
import {
Skyflow,
generateBearerToken,
isExpired,
setLogLevel,
LogLevel,
} from "skyflow-node";

setLogLevel(LogLevel.DEBUG);
let bearerToken = "";
const filePath = "<YOUR_CREDENTIALS_FILE_PATH>";

const skyflow = Skyflow.init({
vaultID: "<VAULT_ID>",
vaultURL: "<VAULT_URL>",
getBearerToken: () => {
return new Promise((resolve, reject) => {
if (!isExpired(bearerToken)) {
resolve(bearerToken);
} else {
generateBearerToken(filePath)
.then((response) => {
bearerToken = response.accessToken;
resolve(bearerToken);
})
.catch((error) => {
reject(error);
});
}
});
},
});

const result = skyflow.insert(
{
records: [
{
fields: {
expiry_date: "12/2026",
card_number: "411111111111111",
namee: "john doe",
},
table: "cards",
},
{
fields: {
expiry_date: "12/2027",
card_number: "411111111111111",
name: "jane doe",
},
table: "cards",
},
],
},
{
tokens: true,
continueOnError: true,
}
);

result
.then((response) => {
console.log("insert result:");
console.log(JSON.stringify(response));
})
.catch((error) => {
console.log("insert error:");
console.log(JSON.stringify(error));
});

0 comments on commit 0232f95

Please sign in to comment.