diff --git a/CHANGELOG.md b/CHANGELOG.md index 328bdef..d00b897 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/samples/insert_upsert_sample.py b/samples/insert_upsert_sample.py new file mode 100644 index 0000000..aec06c4 --- /dev/null +++ b/samples/insert_upsert_sample.py @@ -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('') + return bearerToken + + +try: + config = Configuration( + '', '', token_provider) + client = Client(config) + + upsertOption = UpsertOption(table='',column='') + options = InsertOptions(tokens=True,upsert=[upsertOption]) + + data = { + 'records': [ + { + 'table': '', + 'fields': { + '': '' + } + } + ] + } + response = client.insert(data, options=options) + print('Response:', response) +except SkyflowError as e: + print('Error Occurred:', e) diff --git a/skyflow/vault/_insert.py b/skyflow/vault/_insert.py index cd76989..94660f7 100644 --- a/skyflow/vault/_insert.py +++ b/skyflow/vault/_insert.py @@ -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): diff --git a/tests/vault/test_insert.py b/tests/vault/test_insert.py index 2091342..75b2cff 100644 --- a/tests/vault/test_insert.py +++ b/tests/vault/test_insert.py @@ -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: