Skip to content

Commit e5286f7

Browse files
SK-2030 flowdb sdk with get, delete example (#172)
1 parent fa78cf5 commit e5286f7

2 files changed

Lines changed: 218 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.example;
2+
3+
import com.skyflow.api.ApiClient;
4+
import com.skyflow.api.core.ApiClientApiException;
5+
import com.skyflow.api.core.RequestOptions;
6+
import com.skyflow.api.resources.flowservice.FlowserviceClient;
7+
import com.skyflow.api.resources.flowservice.requests.V1DeleteRequest;
8+
import com.skyflow.api.types.V1DeleteResponse;
9+
import okhttp3.OkHttpClient;
10+
import okhttp3.Request;
11+
12+
import java.util.ArrayList;
13+
import java.util.List;
14+
15+
/**
16+
* This example demonstrates how to use the Skyflow SDK to delete records from flowdb vault.
17+
* by specifying the vault configurations, credentials, and record IDs to delete.
18+
* <p>
19+
* Steps include:
20+
* 1. Setting up the auth client.
21+
* 2. Creating a Skyflow client.
22+
* 3. Setting up vault configurations.
23+
* 4. Creating a delete request with the vaultId, tableName, and skyflow IDs.
24+
* 5. Deleting records from the specified vault using record Skyflow IDs and table names.
25+
*/
26+
27+
public class DeleteExample {
28+
29+
public static void deleteRecords(FlowserviceClient client) {
30+
// Step 3: Setting up vault configurations.
31+
String vaultId = "<VAULT_ID>"; // Replace with the vault ID.
32+
String tableName = "<TABLE_NAME>"; // Replace with the table name in the vault.
33+
34+
// List of Skyflow IDs to delete the record
35+
List<String> skyflowIDs = new ArrayList<>();
36+
skyflowIDs.add("<SKYFLOW_ID_1>"); // Replace with the record Skyflow ID to delete.
37+
skyflowIDs.add("<SKYFLOW_ID_2>");
38+
39+
try {
40+
// Step 4: Creating a delete request with the vaultId, tableName, and skyflow IDs.
41+
V1DeleteRequest deleteRequest = V1DeleteRequest.builder()
42+
.vaultId(vaultId)
43+
.tableName(tableName)
44+
.skyflowIDs(skyflowIDs)
45+
.build();
46+
47+
// Setting up request options
48+
RequestOptions requestOptions = RequestOptions.builder()
49+
.timeout(5000) // Replace with the desired timeout in milliseconds.
50+
.build();
51+
52+
// Step 5: Deleting records from the specified vault using record Skyflow IDs and table names.
53+
V1DeleteResponse deleteResponse = client.delete(deleteRequest, requestOptions);
54+
System.out.println("Delete Response: " + deleteResponse);
55+
} catch (Exception ex) {
56+
System.out.println("Error during deleting the record: " + ex);
57+
ex.printStackTrace();
58+
}
59+
}
60+
61+
public static void main(String[] args) {
62+
// Step 1: Setting up the auth client.
63+
String token = "<BEARER_TOKEN>"; // Replace with the actual bearer token.
64+
OkHttpClient authClient = new OkHttpClient.Builder().addInterceptor(chain -> {
65+
Request original = chain.request();
66+
Request requestWithAuth = original.newBuilder()
67+
.header("Authorization", "Bearer " + token)
68+
.build();
69+
return chain.proceed(requestWithAuth);
70+
}).build();
71+
72+
// Step 2: Creating a Skyflow client.
73+
ApiClient skyflowApiClient = ApiClient.builder()
74+
.url("<VAULT_URL>") // Replace with the vault URL.
75+
.httpClient(authClient)
76+
.build();
77+
FlowserviceClient flowserviceClient = skyflowApiClient.flowservice();
78+
79+
// Call the deleteRecords method to delete records from the vault.
80+
deleteRecords(flowserviceClient);
81+
82+
}
83+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package com.example;
2+
3+
import com.skyflow.api.ApiClient;
4+
import com.skyflow.api.core.ApiClientApiException;
5+
import com.skyflow.api.core.RequestOptions;
6+
import com.skyflow.api.resources.flowservice.FlowserviceClient;
7+
import com.skyflow.api.resources.flowservice.requests.V1GetRequest;
8+
import com.skyflow.api.types.V1ColumnRedactions;
9+
import com.skyflow.api.types.V1GetResponse;
10+
import okhttp3.OkHttpClient;
11+
import okhttp3.Request;
12+
13+
import java.util.ArrayList;
14+
import java.util.List;
15+
16+
/**
17+
* This example demonstrates how to use the Skyflow SDK to securely get records from flowdb vault based on the Skyflow Ids & column values.
18+
* It includes:
19+
* 1. Setting up the auth client.
20+
* 2. Creating a Skyflow client.
21+
* 3. Setting up vault configurations.
22+
* 4. Creating a get request with the vaultId, tableName, and skyflowIDs.
23+
* 5. Getting records using Skyflow IDs and column values.
24+
*/
25+
26+
public class GetExample {
27+
28+
// Example 1: Get records by Skyflow IDs from the flowdb vault.
29+
public static void getRecordsById(FlowserviceClient client, String vaultId, String tableName,
30+
List<String> skyflowIDs, Integer limit, Integer offset, RequestOptions requestOptions) {
31+
try {
32+
// Step 4: Creating a get request with the vaultId, tableName, and skyflowIDs.
33+
V1GetRequest getRequest = V1GetRequest.builder()
34+
.vaultId(vaultId)
35+
.tableName(tableName)
36+
.skyflowIDs(skyflowIDs)
37+
.limit(limit)
38+
.offset(offset)
39+
.build();
40+
41+
// Step 5: Getting records using Skyflow IDs
42+
V1GetResponse records = client.get(getRequest, requestOptions);
43+
System.out.println("Get Response by id: " + records);
44+
} catch (Exception ex) {
45+
System.out.println("Error during get by id: " + ex);
46+
ex.printStackTrace();
47+
}
48+
}
49+
50+
// Example 2: Get records by column values & column redaction from the flowdb vault.
51+
public static void getRecordsByColumnValues(FlowserviceClient client, String vaultId, String tableName,
52+
List<String> skyflowIDs, Integer limit, Integer offset, RequestOptions requestOptions) {
53+
try {
54+
// Creating a list of column values to get the records.
55+
List<String> columnValues = new ArrayList<>();
56+
columnValues.add("<COLUMN_1>"); // Replace with the column name present in the table.
57+
columnValues.add("<COLUMN_2>");
58+
59+
// (Optional) Creating a list of column redactions to get the records in redacted format.
60+
List<V1ColumnRedactions> columnRedactions = new ArrayList<>();
61+
V1ColumnRedactions column1Redaction = V1ColumnRedactions.builder()
62+
.redaction("<COLUMN_NAME_1_REDACTION>") // Replace with the redaction.
63+
.columnName("<COLUMN_NAME_1>") // Replace with the column name present in the table.
64+
.build();
65+
66+
V1ColumnRedactions column2Redaction = V1ColumnRedactions.builder()
67+
.redaction("<COLUMN_NAME_2_REDACTION>") // Replace with the redaction.
68+
.columnName("<COLUMN_NAME_2>") // Replace with the column name present in the table.
69+
.build();
70+
71+
columnRedactions.add(column1Redaction);
72+
columnRedactions.add(column2Redaction);
73+
74+
// Step 4: Get request with column values and column redactions.
75+
V1GetRequest getRecordsByColumnValuesRequest = V1GetRequest.builder()
76+
.vaultId(vaultId)
77+
.skyflowIDs(skyflowIDs)
78+
.tableName(tableName)
79+
.columnRedactions(columnRedactions)
80+
.columns(columnValues)
81+
.limit(limit)
82+
.offset(offset)
83+
.build();
84+
85+
// Step 5: Getting records using column values.
86+
V1GetResponse records = client.get(getRecordsByColumnValuesRequest, requestOptions);
87+
System.out.println("Get Response by column values: " + records);
88+
} catch (Exception ex) {
89+
System.out.println("Error during get by column values: " + ex);
90+
ex.printStackTrace();
91+
}
92+
}
93+
94+
public static void main(String[] args) {
95+
// Step 1: Setting up the auth client.
96+
String token = "<BEARER_TOKEN>"; // Replace with the actual bearer token.
97+
OkHttpClient authClient = new OkHttpClient.Builder().addInterceptor(chain -> {
98+
Request original = chain.request();
99+
Request requestWithAuth = original.newBuilder()
100+
.header("Authorization", "Bearer " + token)
101+
.build();
102+
return chain.proceed(requestWithAuth);
103+
}).build();
104+
105+
// Step 2: Creating a Skyflow client.
106+
ApiClient skyflowApiClient = ApiClient.builder()
107+
.url("<VAULT_URL>") // Replace with the vault URL.
108+
.httpClient(authClient)
109+
.build();
110+
FlowserviceClient flowserviceClient = skyflowApiClient.flowservice();
111+
112+
// Step 3: Setting up vault configurations.
113+
String vaultId = "<VAULT_ID>"; // Replace with the vault ID.
114+
String tableName = "<TABLE_NAME>"; // Replace with the table name in the vault.
115+
116+
// List of Skyflow IDs to get the record.
117+
List<String> skyflowIDs = new ArrayList<>();
118+
skyflowIDs.add("<SKYFLOW_ID_1>"); // Replace with the record Skyflow ID
119+
skyflowIDs.add("<SKYFLOW_ID_2>");
120+
121+
// Setting up request options
122+
RequestOptions requestOptions = RequestOptions.builder()
123+
.timeout(5000) // Replace with the desired timeout in milliseconds.
124+
.build();
125+
126+
// The limit and offset are optional parameters.
127+
Integer limit = 5; // Replace with the desired limit.
128+
Integer offset = 0; // Replace with the desired offset.
129+
130+
131+
// Call the getRecordsById and getRecordsByColumnValues methods to get records from the vault.
132+
getRecordsById(flowserviceClient, vaultId, tableName, skyflowIDs, limit, offset, requestOptions);
133+
getRecordsByColumnValues(flowserviceClient, vaultId, tableName, skyflowIDs, limit, offset, requestOptions);
134+
}
135+
}

0 commit comments

Comments
 (0)