Skip to content

Commit 716f53f

Browse files
Merge pull request #38 from skyflowapi/SK-145-README-upsert
SK-145/ README for Upsert support
2 parents 5ecbab6 + a006979 commit 716f53f

File tree

3 files changed

+153
-18
lines changed

3 files changed

+153
-18
lines changed

CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

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

5+
## [1.5.0] - 2022-12-07
6+
### Added
7+
- Upsert support for `insert` method.
8+
9+
510
## [1.4.0] - 2022-04-12
611

712
### Added
8-
- support for application/x-www-form-urlencoded and multipart/form-data content-type's in connections.
13+
- Support for application/x-www-form-urlencoded and multipart/form-data content-type's in connections.
914

1015
## [1.3.1] - 2022-03-29
1116

README.md

+78-17
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,19 @@ skyflowClient := Skyflow.Init(configuration)
112112

113113
All Vault APIs must be invoked using a skyflowClient instance.
114114

115-
#### Insert
115+
### Insert data into the vault
116+
117+
To insert data into your vault, use the **Insert(records map[string]interface{}, options common.InsertOptions)** method of the Skyflow client. The **insertInput** parameter requires a `records` key and takes an array of records to insert as a value into the vault. The `options` parameter is a InsertOptions object that provides further options, including Upsert operations, for your insert call, as shown below.
118+
119+
Insert call schema:
116120

117-
To insert data into your vault, use the **insert(records map[string]interface{}, options common.InsertOptions)** method of the Skyflow client. The first parameter insertInput must have a `records` key and takes an array of records to be inserted into the vault as a value. The second parameter `options` is a InsertOptions object that provides further options for your insert call, as shown below.
118121
```go
119122
import (
120123
Skyflow "github.com/skyflowapi/skyflow-go/skyflow/client"
121124
"github.com/skyflowapi/skyflow-go/skyflow/common"
122125
)
123126

124-
//initialize skyflowClient
127+
//Initialize the SkyflowClient.
125128

126129
var records = make(map[string] interface {})
127130

@@ -136,30 +139,32 @@ recordsArray = append(recordsArray, record)
136139

137140
records["records"] = recordsArray
138141

139-
// Indicates whether or not tokens should be returned for the inserted data. Defaults to 'true'
142+
var upsertArray []common.UpsertOptions
143+
var upsertOption = common.UpsertOptions{Table:"<table_name>",Column:"<column_name>"}
144+
upsertArray = append(upsertArray,upsertOption)
145+
140146
options = common.InsertOptions {
141-
Tokens: true
147+
Tokens: true //Optional, indicates whether tokens should be returned for the inserted data. This value defaults to "true".
148+
Upsert: upsertArray //Optional, upsert support.
142149
}
143150

144151
res, err: = skyflowClient.Insert(records, options)
145152
```
146153

147-
An [example](https://github.com/skyflowapi/skyflow-go/blob/main/samples/vault-api/insert.go) of an Insert call is given below:
148-
154+
[Insert call example](https://github.com/skyflowapi/skyflow-go/blob/main/samples/vault-api/insert.go):
149155

150156
```go
151157
package main
152158

153159
import (
154160
"fmt"
155-
156161
Skyflow "github.com/skyflowapi/skyflow-go/skyflow/client"
157162
"github.com/skyflowapi/skyflow-go/skyflow/common"
158163
)
159164

160165
func main() {
161166

162-
//initialize skyflowClient
167+
//Initialize the SkyflowClient.
163168

164169
var records = make(map[string] interface {})
165170
var record = make(map[string] interface {})
@@ -201,13 +206,69 @@ Sample response :
201206

202207
```
203208

204-
205-
#### Detokenize
209+
[Upsert call example](https://github.com/skyflowapi/skyflow-go/blob/main/samples/vault-api/upsert.go):
206210

207-
In order to retrieve data from your vault using tokens that you have previously generated for that data, you can use the **detokenize(records map[string]interface{})** method. The first parameter must have a `records` key that takes an array of tokens to be fetched from the vault, as shown below.
211+
```go
212+
package main
208213

214+
import (
215+
"fmt"
216+
Skyflow "github.com/skyflowapi/skyflow-go/skyflow/client"
217+
"github.com/skyflowapi/skyflow-go/skyflow/common"
218+
)
219+
220+
func main() {
221+
222+
//Initialize the SkyflowClient.
223+
224+
var records = make(map[string] interface {})
225+
var record = make(map[string] interface {})
226+
record["table"] = "cards"
227+
var fields = make(map[string] interface {})
228+
fields["cardNumber"] = "411111111111"
229+
fields["fullname"] = "name"
230+
record["fields"] = fields
231+
var recordsArray[] interface {}
232+
recordsArray = append(recordsArray, record)
233+
records["records"] = recordsArray
209234

235+
//Create an upsert array.
210236

237+
var upsertArray []common.UpsertOptions
238+
var upsertOption = common.UpsertOptions{Table:"cards",Column:"cardNumber"}
239+
upsertArray = append(upsertArray,upsertOption)
240+
241+
var options = common.InsertOptions {
242+
Tokens: true
243+
Upsert: upsertArray
244+
}
245+
246+
res, err: = skyflowClient.Insert(records, options)
247+
248+
if err == nil {
249+
fmt.Println(res.Records)
250+
}
251+
}
252+
```
253+
254+
Sample response :
255+
256+
```json
257+
{
258+
"records": [
259+
{
260+
"table": "cards",
261+
"fields": {
262+
"cardNumber": "f37186-e7e2-466f-91e5-48e2bcbc1",
263+
"fullname": "1989cb56-63a-4482-adf-1f74cd1a5"
264+
}
265+
}
266+
]
267+
}
268+
```
269+
270+
#### Detokenize
271+
To retrieve tokens from your vault, you can use the **Detokenize(records map[string]interface{})** method.The `records` parameter takes an array of SkyflowIDs to return, as shown below:
211272

212273
```go
213274
import (
@@ -289,9 +350,9 @@ Sample response:
289350
}
290351
```
291352

292-
#### Get By Id
353+
#### GetById
293354

294-
In order to retrieve data from your vault using SkyflowIDs, use the **getById(records map[string]interface{})** method. The `records` parameter takes a map that should contain an array of SkyflowIDs to be fetched, as shown below:
355+
In order to retrieve data from your vault using SkyflowIDs, use the **GetById(records map[string]interface{})** method. The `records` parameter takes a map that has an array of SkyflowIDs to return, as shown below:
295356

296357
```go
297358
import (
@@ -389,11 +450,11 @@ Sample response:
389450
}
390451
```
391452

392-
### Invoke-connection
453+
### InvokeConnection
393454

394-
Using InvokeConnection, end-user applications can integrate checkout/card issuance flow with their apps/systems. To invoke connection, use the invokeConnection(config ConnectionConfig) method of the Skyflow client. The config object must have `connectionURL`,`methodName` and remaining are optional.
455+
End-user apps can use InvokeConnection to integrate checkout and card issuance flows with their apps and systems. To invoke a connection, use the invokeConnection(config ConnectionConfig) method of the Skyflow client. The config object must have `connectionURL`,`methodName` and the remaining are optional.
395456

396-
Using the InvokeConnection method, you can integrate their server-side application with third party APIs and services without directly handling sensitive data. Prior to invoking the `InvokeConnection` method, you must have created a connection and have a connectionURL already generated. Once you have the connectionURL, you can invoke a connection by using the **invokeConnection(config ConnectionConfig)** method. The config parameter must include a `connectionURL` and `methodName`. The other fields are optional.
457+
The InvokeConnection method lets you bypass handling sensitive data by integrating third-party server-side application using APIs. Before invoking the `InvokeConnection` method, you must create a connection and generate a connectionURL. Once you have the connectionURL, you can invoke a connection by using the **InvokeConnection(config ConnectionConfig)** method. The config parameter must include a `connectionURL` and `methodName`. The other fields are optional.
397458

398459
```go
399460

samples/vaultapi/upsert.go

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
Copyright (c) 2022 Skyflow, Inc.
3+
*/
4+
package main
5+
6+
import (
7+
"fmt"
8+
9+
logger "github.com/skyflowapi/skyflow-go/commonutils/logwrapper"
10+
saUtil "github.com/skyflowapi/skyflow-go/serviceaccount/util"
11+
Skyflow "github.com/skyflowapi/skyflow-go/skyflow/client"
12+
"github.com/skyflowapi/skyflow-go/skyflow/common"
13+
)
14+
15+
var bearerToken = ""
16+
17+
func GetToken() (string, error) {
18+
19+
filePath := "<file_path>"
20+
if saUtil.IsExpired(bearerToken) {
21+
newToken, err := saUtil.GenerateBearerToken(filePath)
22+
if err != nil {
23+
return "", err
24+
} else {
25+
bearerToken = newToken.AccessToken
26+
return bearerToken, nil
27+
}
28+
}
29+
return bearerToken, nil
30+
}
31+
32+
func main() {
33+
34+
defer func() {
35+
if err := recover(); err != nil {
36+
fmt.Println("error : ", err)
37+
}
38+
}()
39+
logger.SetLogLevel(logger.INFO) // Set loglevel to INFO
40+
configuration := common.Configuration{VaultID: "<vault_id>", VaultURL: "<vault_url>", TokenProvider: GetToken}
41+
var client = Skyflow.Init(configuration)
42+
43+
var records = make(map[string]interface{})
44+
var record = make(map[string]interface{})
45+
record["table"] = "cards"
46+
var fields = make(map[string]interface{})
47+
fields["cardNumber"] = "4111111111111111"
48+
fields["fullname"] = "name"
49+
record["fields"] = fields
50+
var recordsArray []interface{}
51+
recordsArray = append(recordsArray, record)
52+
records["records"] = recordsArray
53+
54+
var upsertArray []common.UpsertOptions
55+
var upsertOption = common.UpsertOptions{Table:"cards",Column:"cardNumber"}
56+
upsertArray = append(upsertArray,upsertOption)
57+
58+
var options = common.InsertOptions {
59+
Tokens: true
60+
Upsert: upsertArray
61+
}
62+
63+
res, err := client.Insert(records, options)
64+
if err == nil {
65+
fmt.Println("Records : ", res.Records)
66+
} else {
67+
panic(err.GetMessage())
68+
}
69+
}

0 commit comments

Comments
 (0)