-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from skyflowapi/SK-47/upsert-support
SK-47 add upsert support in insert method options.
- Loading branch information
Showing
7 changed files
with
176 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
''' | ||
Copyright (c) 2022 Skyflow, Inc. | ||
''' | ||
from skyflow.errors import SkyflowError | ||
from skyflow.service_account import generate_bearer_token, is_expired | ||
from skyflow.vault import Client, InsertOptions, Configuration, UpsertOption | ||
|
||
# cache token for reuse | ||
bearerToken = '' | ||
|
||
def token_provider(): | ||
global bearerToken | ||
if is_expired(bearerToken): | ||
bearerToken, _ = generate_bearer_token('<YOUR_CREDENTIALS_FILE_PATH>') | ||
return bearerToken | ||
|
||
|
||
try: | ||
config = Configuration( | ||
'<YOUR_VAULT_ID>', '<YOUR_VAULT_URL>', token_provider) | ||
client = Client(config) | ||
|
||
upsertOption = UpsertOption(table='<TABLE_NAME>',column='<UNIQUE_COLUMN_NAME>') | ||
options = InsertOptions(tokens=True,upsert=[upsertOption]) | ||
|
||
data = { | ||
'records': [ | ||
{ | ||
'table': '<TABLE_NAME>', | ||
'fields': { | ||
'<FIELDNAME>': '<VALUE>' | ||
} | ||
} | ||
] | ||
} | ||
response = client.insert(data, options=options) | ||
print('Response:', response) | ||
except SkyflowError as e: | ||
print('Error Occurred:', e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters