-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathget-column-values.ts
More file actions
96 lines (85 loc) · 3.15 KB
/
get-column-values.ts
File metadata and controls
96 lines (85 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import {
Env,
GetOptions,
LogLevel,
Skyflow,
GetColumnRequest,
Credentials,
SkyflowConfig,
VaultConfig,
SkyflowError,
GetResponse,
GetResponseData
} from 'skyflow-node';
/**
* Skyflow Secure Column-Based Retrieval Example
*
* This example demonstrates how to:
* 1. Configure credentials
* 2. Set up vault configuration
* 3. Create a column-based get request
* 4. Handle response and errors
*/
async function performSecureColumnRetrieval() {
try {
// Step 1: Configure Credentials
const credentials: Credentials = {
path: 'path-to-credentials-json', // Path to credentials file
};
// Step 2: Configure Vault
const primaryVaultConfig: VaultConfig = {
vaultId: 'your-vault-id', // Unique vault identifier
clusterId: 'your-cluster-id', // From vault URL
env: Env.PROD, // Deployment environment
credentials: credentials // Authentication method
};
// Step 3: Configure Skyflow Client
const skyflowConfig: SkyflowConfig = {
vaultConfigs: [primaryVaultConfig],
logLevel: LogLevel.ERROR, // Logging verbosity
};
// Initialize Skyflow Client
const skyflowClient: Skyflow = new Skyflow(skyflowConfig);
// Step 4: Prepare Column-Based Retrieval Data
const columnValues: Array<string> = [
'value1', // Example Unique Column value 1
'value2', // Example Unique Column value 2
];
const tableName: string = 'table-name'; // Replace with your actual table name
const columnName: string = 'column-name'; // Column name configured as unique in the schema
// Step 5: Create Get Column Request
const getRequest: GetColumnRequest = new GetColumnRequest(
tableName,
columnName,
columnValues // Column values of the records to return
);
// Step 6: Configure Get Options
const getOptions: GetOptions = new GetOptions();
getOptions.setReturnTokens(true); // Optional: Get tokens for retrieved data
// Step 7: Perform Secure Retrieval
const response: GetResponse = await skyflowClient
.vault(primaryVaultConfig.vaultId)
.get(getRequest, getOptions);
// Handle Successful Response
console.log('Column-based retrieval successful:', response);
if (response.data != null) {
response.data.forEach((record: GetResponseData) => {
console.log("Get data:", record);
// Handle record data
});
}
} catch (error) {
// Comprehensive Error Handling
if (error instanceof SkyflowError) {
console.error('Skyflow Specific Error:', {
code: error.error?.http_code,
message: error.message,
details: error.error?.details,
});
} else {
console.error('Unexpected Error:', error);
}
}
}
// Invoke the secure column retrieval function
performSecureColumnRetrieval();