Skip to content

Commit

Permalink
SK-164 add samples, changelog with upsert support info.
Browse files Browse the repository at this point in the history
  • Loading branch information
yaswanth-pula-skyflow committed Dec 1, 2022
1 parent 5e8347f commit 8a8e4c9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

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

## [1.16.2] - 2022-06-28
## [1.7.0] - 2022-12-06
### Added
- `upsert` support for insert method.

## [1.6.2] - 2022-06-28

### Added
- Copyright header to all files
Expand Down
39 changes: 39 additions & 0 deletions samples/insert_upsert_sample.py
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)
1 change: 0 additions & 1 deletion skyflow/vault/_insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ def getUpsertColumn(tableName, upsertOptions):
for upsertOption in upsertOptions:
if tableName == upsertOption.table:
uniqueColumn = upsertOption.column
print(uniqueColumn)
return uniqueColumn

def validateUpsertOptions(upsertOptions):
Expand Down
1 change: 0 additions & 1 deletion tests/vault/test_insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ def testValidUpsertOptions(self):
validateUpsertOptions(upsertOptions=[UpsertOption(table=123,column='')])
except SkyflowError as e:
self.assertEqual(e.code, SkyflowErrorCodes.INVALID_INPUT.value)
print(e.message)
self.assertEqual(
e.message, SkyflowErrorMessages.INVALID_UPSERT_TABLE_TYPE.value % 0)
try:
Expand Down

0 comments on commit 8a8e4c9

Please sign in to comment.