def setUp(self): self.set_up() self.row = get_row(with_sid=False) self.key = {'fld_id': 1} self.put_request = PutRequest().set_value( self.row).set_table_name(table_name) self.version = self.handle.put(self.put_request).get_version() self.get_request = GetRequest().set_key( self.key).set_table_name(table_name) self.delete_request = DeleteRequest().set_key( self.key).set_table_name(table_name).set_timeout(timeout)
def setUp(self): TestBase.set_up(self) self.row = {'fld_id': 1, 'fld_long': 2147483648, 'fld_float': 3.1414999961853027, 'fld_double': 3.1415, 'fld_bool': True, 'fld_str': '{"name": u1, "phone": null}', 'fld_bin': bytearray(pack('>i', 4)), 'fld_time': datetime.now(), 'fld_num': Decimal(5), 'fld_json': {'a': '1', 'b': None, 'c': '3'}, 'fld_arr': ['a', 'b', 'c'], 'fld_map': {'a': '1', 'b': '2', 'c': '3'}, 'fld_rec': {'fld_id': 1, 'fld_bool': False, 'fld_str': None}} self.key = {'fld_id': 1} self.put_request = PutRequest().set_value(self.row).set_table_name( table_name) self.version = self.handle.put(self.put_request).get_version() self.get_request = GetRequest().set_key(self.key).set_table_name( table_name) self.delete_request = DeleteRequest().set_key(self.key).set_table_name( table_name).set_timeout(timeout)
class TestDelete(unittest.TestCase, TestBase): @classmethod def setUpClass(cls): TestBase.set_up_class() create_statement = ( 'CREATE TABLE ' + table_name + '(fld_id INTEGER, fld_long LONG, \ fld_float FLOAT, fld_double DOUBLE, fld_bool BOOLEAN, fld_str STRING, \ fld_bin BINARY, fld_time TIMESTAMP(6), fld_num NUMBER, fld_json JSON, \ fld_arr ARRAY(STRING), fld_map MAP(STRING), \ fld_rec RECORD(fld_id LONG, fld_bool BOOLEAN, fld_str STRING), \ PRIMARY KEY(fld_id)) USING TTL 2 DAYS') create_request = TableRequest().set_statement( create_statement).set_table_limits(TableLimits(5000, 5000, 50)) cls._result = TestBase.table_request(create_request, State.ACTIVE) global hour_in_milliseconds hour_in_milliseconds = 60 * 60 * 1000 @classmethod def tearDownClass(cls): TestBase.tear_down_class() def setUp(self): TestBase.set_up(self) self.row = {'fld_id': 1, 'fld_long': 2147483648, 'fld_float': 3.1414999961853027, 'fld_double': 3.1415, 'fld_bool': True, 'fld_str': '{"name": u1, "phone": null}', 'fld_bin': bytearray(pack('>i', 4)), 'fld_time': datetime.now(), 'fld_num': Decimal(5), 'fld_json': {'a': '1', 'b': None, 'c': '3'}, 'fld_arr': ['a', 'b', 'c'], 'fld_map': {'a': '1', 'b': '2', 'c': '3'}, 'fld_rec': {'fld_id': 1, 'fld_bool': False, 'fld_str': None}} self.key = {'fld_id': 1} self.put_request = PutRequest().set_value(self.row).set_table_name( table_name) self.version = self.handle.put(self.put_request).get_version() self.get_request = GetRequest().set_key(self.key).set_table_name( table_name) self.delete_request = DeleteRequest().set_key(self.key).set_table_name( table_name).set_timeout(timeout) def tearDown(self): TestBase.tear_down(self) def testDeleteSetIllegalKey(self): self.assertRaises(IllegalArgumentException, self.delete_request.set_key, 'IllegalKey') def testDeleteSetIllegalKeyFromJson(self): self.assertRaises(ValueError, self.delete_request.set_key_from_json, 'IllegalJson') self.delete_request.set_key_from_json('{"invalid_field": "key"}') self.assertRaises(IllegalArgumentException, self.handle.delete, self.delete_request) def testDeleteSetIllegalMatchVersion(self): self.assertRaises(IllegalArgumentException, self.delete_request.set_match_version, 'IllegalMatchVersion') def testDeleteSetIllegalTimeout(self): self.assertRaises(IllegalArgumentException, self.delete_request.set_timeout, 'IllegalTimeout') self.assertRaises(IllegalArgumentException, self.delete_request.set_timeout, 0) self.assertRaises(IllegalArgumentException, self.delete_request.set_timeout, -1) def testDeleteSetIllegalTableName(self): self.assertRaises(IllegalArgumentException, self.delete_request.set_table_name, {'name': table_name}) self.delete_request.set_table_name('IllegalTable') self.assertRaises(TableNotFoundException, self.handle.delete, self.delete_request) def testDeleteSetIllegalReturnRow(self): self.assertRaises(IllegalArgumentException, self.delete_request.set_return_row, 'IllegalReturnRow') def testDeleteWithoutKey(self): self.delete_request.set_key(None) self.assertRaises(IllegalArgumentException, self.handle.delete, self.delete_request) def testDeleteGets(self): self.delete_request.set_match_version( self.version).set_return_row(True) self.assertEqual(self.delete_request.get_key(), self.key) self.assertEqual(self.delete_request.get_match_version(), self.version) self.assertEqual(self.delete_request.get_timeout(), timeout) self.assertEqual(self.delete_request.get_table_name(), table_name) self.assertTrue(self.delete_request.get_return_row()) def testDeleteIllegalRequest(self): self.assertRaises(IllegalArgumentException, self.handle.delete, 'IllegalRequest') def testDeleteNormal(self): self.delete_request.set_return_row(True) result = self.handle.delete(self.delete_request) self.assertTrue(result.get_success()) self.assertIsNone(result.get_existing_value()) self.assertIsNone(result.get_existing_version()) self.assertEqual(result.get_read_kb(), 1) self.assertEqual(result.get_read_units(), 2) self.assertEqual(result.get_write_kb(), 1) self.assertEqual(result.get_write_units(), 1) result = self.handle.get(self.get_request) self.assertIsNone(result.get_value()) self.assertIsNone(result.get_version()) self.assertEqual(result.get_expiration_time(), 0) self.assertEqual(result.get_read_kb(), 1) self.assertEqual(result.get_read_units(), 2) self.assertEqual(result.get_write_kb(), 0) self.assertEqual(result.get_write_units(), 0) def testDeleteNonExisting(self): self.delete_request.set_key({'fld_id': 2}) result = self.handle.delete(self.delete_request) self.assertFalse(result.get_success()) self.assertIsNone(result.get_existing_value()) self.assertIsNone(result.get_existing_version()) self.assertEqual(result.get_read_kb(), 1) self.assertEqual(result.get_read_units(), 2) self.assertEqual(result.get_write_kb(), 0) self.assertEqual(result.get_write_units(), 0) def testDeleteIfVersion(self): self.row.update({'fld_long': 2147483649}) self.put_request.set_value(self.row) version = self.handle.put(self.put_request).get_version() # delete failed because version not match self.delete_request.set_match_version(self.version) result = self.handle.delete(self.delete_request) self.assertFalse(result.get_success()) self.assertIsNone(result.get_existing_value()) self.assertIsNone(result.get_existing_version()) self.assertEqual(result.get_read_kb(), 1) self.assertEqual(result.get_read_units(), 2) self.assertEqual(result.get_write_kb(), 0) self.assertEqual(result.get_write_units(), 0) result = self.handle.get(self.get_request) self.assertEqual(result.get_value(), self.row) self.assertEqual(result.get_version().get_bytes(), version.get_bytes()) self.assertNotEqual(result.get_expiration_time(), 0) self.assertEqual(result.get_read_kb(), 1) self.assertEqual(result.get_read_units(), 2) self.assertEqual(result.get_write_kb(), 0) self.assertEqual(result.get_write_units(), 0) # delete succeed when version match self.delete_request.set_match_version(version) result = self.handle.delete(self.delete_request) self.assertTrue(result.get_success()) self.assertIsNone(result.get_existing_value()) self.assertIsNone(result.get_existing_version()) self.assertEqual(result.get_read_kb(), 1) self.assertEqual(result.get_read_units(), 2) self.assertEqual(result.get_write_kb(), 1) self.assertEqual(result.get_write_units(), 1) result = self.handle.get(self.get_request) self.assertIsNone(result.get_value()) self.assertIsNone(result.get_version()) self.assertEqual(result.get_expiration_time(), 0) self.assertEqual(result.get_read_kb(), 1) self.assertEqual(result.get_read_units(), 2) self.assertEqual(result.get_write_kb(), 0) self.assertEqual(result.get_write_units(), 0) def testDeleteIfVersionWithReturnRow(self): self.row.update({'fld_long': 2147483649}) self.put_request.set_value(self.row) version = self.handle.put(self.put_request).get_version() # delete failed because version not match self.delete_request.set_match_version( self.version).set_return_row(True) result = self.handle.delete(self.delete_request) self.assertFalse(result.get_success()) self.assertEqual(result.get_existing_value(), self.row) self.assertEqual(result.get_existing_version().get_bytes(), version.get_bytes()) self.assertEqual(result.get_read_kb(), 1) self.assertEqual(result.get_read_units(), 2) self.assertEqual(result.get_write_kb(), 0) self.assertEqual(result.get_write_units(), 0) result = self.handle.get(self.get_request) self.assertEqual(result.get_value(), self.row) self.assertEqual(result.get_version().get_bytes(), version.get_bytes()) self.assertNotEqual(result.get_expiration_time(), 0) self.assertEqual(result.get_read_kb(), 1) self.assertEqual(result.get_read_units(), 2) self.assertEqual(result.get_write_kb(), 0) self.assertEqual(result.get_write_units(), 0) # delete succeed when version match self.delete_request.set_match_version(version) result = self.handle.delete(self.delete_request) self.assertTrue(result.get_success()) self.assertIsNone(result.get_existing_value()) self.assertIsNone(result.get_existing_version()) self.assertEqual(result.get_read_kb(), 1) self.assertEqual(result.get_read_units(), 2) self.assertEqual(result.get_write_kb(), 1) self.assertEqual(result.get_write_units(), 1) result = self.handle.get(self.get_request) self.assertIsNone(result.get_value()) self.assertIsNone(result.get_version()) self.assertEqual(result.get_expiration_time(), 0) self.assertEqual(result.get_read_kb(), 1) self.assertEqual(result.get_read_units(), 2) self.assertEqual(result.get_write_kb(), 0) self.assertEqual(result.get_write_units(), 0)
def main(): handle = None try: # # Create a handle # handle = get_handle(tenant_id) # # Create a table # statement = 'Create table if not exists ' + table_name + '(id integer, \ sid integer, name string, primary key(shard(sid), id))' print('Creating table: ' + statement) request = TableRequest().set_statement(statement).set_table_limits( TableLimits(30, 10, 1)) result = handle.table_request(request) # # Table creation can take time, depending on the state of the system. # If if fails after 40s, re-run the program # result.wait_for_state(handle, table_name, State.ACTIVE, 50000, 3000) print('After create table') # # Put a few rows # request = PutRequest().set_table_name(table_name) for i in range(10): value = {'id': i, 'sid': 0, 'name': 'myname' + str(i)} request.set_value(value) handle.put(request) print('After put of 10 rows') # # Get the row # request = GetRequest().set_key({ 'id': 1, 'sid': 0 }).set_table_name(table_name) result = handle.get(request) print('After get: ' + str(result)) # # Query, using a range # statement = 'select * from ' + table_name + ' where id > 2 and id < 8' request = QueryRequest().set_statement(statement) result = handle.query(request) print('Query results for: ' + statement) for r in result.get_results(): print('\t' + str(r)) # # Delete the row # request = DeleteRequest().set_key({ 'id': 1, 'sid': 0 }).set_table_name(table_name) result = handle.delete(request) print('After delete: ' + str(result)) # # Get again to show deletion # request = GetRequest().set_key({ 'id': 1, 'sid': 0 }).set_table_name(table_name) result = handle.get(request) print('After get (should be None): ' + str(result)) # # Drop the table # if drop_table: request = TableRequest().set_statement('drop table if exists ' + table_name) result = handle.table_request(request) # # Table drop can take time, depending on the state of the system. # If this wait fails the table will still probably been dropped # result.wait_for_state(handle, table_name, State.DROPPED, 40000, 2000) print('After drop table') else: print('Not dropping table') print('Example is complete') except Exception as e: print(e) traceback.print_exc() finally: # If the handle isn't closed Python will not exit properly if handle is not None: handle.close()
class TestDelete(unittest.TestCase, TestBase): @classmethod def setUpClass(cls): cls.set_up_class() global table_ttl table_ttl = TimeToLive.of_days(2) create_statement = ('CREATE TABLE ' + table_name + '(fld_id INTEGER, fld_long LONG, \ fld_float FLOAT, fld_double DOUBLE, fld_bool BOOLEAN, fld_str STRING, \ fld_bin BINARY, fld_time TIMESTAMP(6), fld_num NUMBER, fld_json JSON, \ fld_arr ARRAY(STRING), fld_map MAP(STRING), \ fld_rec RECORD(fld_id LONG, fld_bool BOOLEAN, fld_str STRING), \ PRIMARY KEY(fld_id)) USING TTL ' + str(table_ttl)) create_request = TableRequest().set_statement( create_statement).set_table_limits(TableLimits(100, 100, 1)) cls.table_request(create_request) @classmethod def tearDownClass(cls): cls.tear_down_class() def setUp(self): self.set_up() self.row = get_row(with_sid=False) self.key = {'fld_id': 1} self.put_request = PutRequest().set_value( self.row).set_table_name(table_name) self.version = self.handle.put(self.put_request).get_version() self.get_request = GetRequest().set_key( self.key).set_table_name(table_name) self.delete_request = DeleteRequest().set_key( self.key).set_table_name(table_name).set_timeout(timeout) def tearDown(self): self.tear_down() def testDeleteSetIllegalKey(self): self.assertRaises(IllegalArgumentException, self.delete_request.set_key, 'IllegalKey') def testDeleteSetIllegalKeyFromJson(self): self.assertRaises(ValueError, self.delete_request.set_key_from_json, 'IllegalJson') self.delete_request.set_key_from_json('{"invalid_field": "key"}') self.assertRaises(IllegalArgumentException, self.handle.delete, self.delete_request) def testDeleteSetIllegalMatchVersion(self): self.assertRaises(IllegalArgumentException, self.delete_request.set_match_version, 'IllegalMatchVersion') def testDeleteSetIllegalTimeout(self): self.assertRaises(IllegalArgumentException, self.delete_request.set_timeout, 'IllegalTimeout') self.assertRaises(IllegalArgumentException, self.delete_request.set_timeout, 0) self.assertRaises(IllegalArgumentException, self.delete_request.set_timeout, -1) def testDeleteSetIllegalTableName(self): self.assertRaises(IllegalArgumentException, self.delete_request.set_table_name, {'name': table_name}) self.delete_request.set_table_name('IllegalTable') self.assertRaises(TableNotFoundException, self.handle.delete, self.delete_request) def testDeleteSetIllegalCompartment(self): self.assertRaises(IllegalArgumentException, self.delete_request.set_compartment, {}) self.assertRaises(IllegalArgumentException, self.delete_request.set_compartment, '') def testDeleteSetIllegalReturnRow(self): self.assertRaises(IllegalArgumentException, self.delete_request.set_return_row, 'IllegalReturnRow') def testDeleteWithoutKey(self): self.delete_request.set_key(None) self.assertRaises(IllegalArgumentException, self.handle.delete, self.delete_request) def testDeleteGets(self): self.delete_request.set_match_version( self.version).set_return_row(True) self.assertEqual(self.delete_request.get_key(), self.key) self.assertIsNone(self.delete_request.get_compartment()) self.assertEqual(self.delete_request.get_match_version(), self.version) self.assertEqual(self.delete_request.get_timeout(), timeout) self.assertEqual(self.delete_request.get_table_name(), table_name) self.assertTrue(self.delete_request.get_return_row()) def testDeleteIllegalRequest(self): self.assertRaises(IllegalArgumentException, self.handle.delete, 'IllegalRequest') def testDeleteNormal(self): self.delete_request.set_return_row(True) result = self.handle.delete(self.delete_request) self._check_delete_result(result) self.check_cost(result, 1, 2, 1, 1) result = self.handle.get(self.get_request) self.check_get_result(result) self.check_cost(result, 1, 2, 0, 0) def testDeleteNonExisting(self): self.delete_request.set_key({'fld_id': 2}) result = self.handle.delete(self.delete_request) self._check_delete_result(result, False) self.check_cost(result, 1, 2, 0, 0) def testDeleteIfVersion(self): self.row['fld_long'] = 2147483649 self.put_request.set_value(self.row) version = self.handle.put(self.put_request).get_version() tb_expect_expiration = table_ttl.to_expiration_time( int(round(time() * 1000))) # delete failed because version not match self.delete_request.set_match_version(self.version) result = self.handle.delete(self.delete_request) self._check_delete_result(result, False) self.check_cost(result, 1, 2, 0, 0) result = self.handle.get(self.get_request) self.check_get_result(result, self.row, version, tb_expect_expiration, TimeUnit.DAYS) self.check_cost(result, 1, 2, 0, 0) # delete succeed when version match self.delete_request.set_match_version(version) result = self.handle.delete(self.delete_request) self._check_delete_result(result) self.check_cost(result, 1, 2, 1, 1) result = self.handle.get(self.get_request) self.check_get_result(result) self.check_cost(result, 1, 2, 0, 0) def testDeleteIfVersionWithReturnRow(self): self.row['fld_long'] = 2147483649 self.put_request.set_value(self.row) version = self.handle.put(self.put_request).get_version() tb_expect_expiration = table_ttl.to_expiration_time( int(round(time() * 1000))) # delete failed because version not match self.delete_request.set_match_version( self.version).set_return_row(True) result = self.handle.delete(self.delete_request) self._check_delete_result(result, False, self.row, version.get_bytes()) self.check_cost(result, 1, 2, 0, 0) result = self.handle.get(self.get_request) self.check_get_result(result, self.row, version, tb_expect_expiration, TimeUnit.DAYS) self.check_cost(result, 1, 2, 0, 0) # delete succeed when version match self.delete_request.set_match_version(version) result = self.handle.delete(self.delete_request) self._check_delete_result(result) self.check_cost(result, 1, 2, 1, 1) result = self.handle.get(self.get_request) self.check_get_result(result) self.check_cost(result, 1, 2, 0, 0) def _check_delete_result(self, result, success=True, value=None, version=None): # check whether success self.assertEqual(result.get_success(), success) # check existing value self.assertEqual(result.get_existing_value(), value) # check existing version ver = result.get_existing_version() (self.assertIsNone(ver) if version is None else self.assertEqual( ver.get_bytes(), version))
def tearDown(self): request = DeleteRequest().set_key(self.key).set_table_name(table_name) self.handle.delete(request) self.tear_down()
def setUp(self): self.set_up() self.shardkeys = [0, 1] self.ids = [0, 1, 2, 3, 4, 5] self.rows = list() self.new_rows = list() self.versions = list() self.requests = list() self.illegal_requests = list() ttl = TimeToLive.of_days(16) for sk in self.shardkeys: self.rows.append(list()) self.new_rows.append(list()) self.versions.append(list()) for i in self.ids: row = get_row() row['fld_sid'] = sk row['fld_id'] = i new_row = deepcopy(row) new_row['fld_long'] = 2147483649 self.rows[sk].append(row) self.new_rows[sk].append(new_row) put_request = PutRequest().set_value(row).set_table_name( table_name).set_ttl(ttl) self.versions[sk].append( self.handle.put(put_request).get_version()) self.old_expect_expiration = ttl.to_expiration_time( int(round(time() * 1000))) self.ttl = TimeToLive.of_hours(1) self.ops_sk = 0 illegal_sk = 1 self.requests.append(PutRequest().set_value( self.new_rows[self.ops_sk][0]).set_table_name(table_name).set_ttl( self.ttl).set_return_row(True)) self.requests.append(PutRequest().set_value(self.new_rows[ self.ops_sk][1]).set_table_name(table_name).set_option( PutOption.IF_ABSENT).set_ttl(self.ttl).set_return_row(True)) self.requests.append(PutRequest().set_value( self.new_rows[self.ops_sk][2]).set_use_table_default_ttl( True).set_table_name(table_name).set_option( PutOption.IF_PRESENT).set_return_row(True)) self.requests.append(PutRequest().set_value( self.new_rows[self.ops_sk][3]).set_table_name(table_name).set_ttl( self.ttl).set_option(PutOption.IF_VERSION).set_match_version( self.versions[self.ops_sk][3]).set_return_row(True)) self.requests.append(DeleteRequest().set_key({ 'fld_sid': self.ops_sk, 'fld_id': 4 }).set_table_name(table_name).set_return_row(True)) self.requests.append(DeleteRequest().set_key({ 'fld_sid': self.ops_sk, 'fld_id': 5 }).set_table_name(table_name).set_return_row(True).set_match_version( self.versions[self.ops_sk][0])) self.illegal_requests.append(DeleteRequest().set_key({ 'fld_sid': self.ops_sk, 'fld_id': 0 }).set_table_name('IllegalUsers')) self.illegal_requests.append(DeleteRequest().set_key({ 'fld_sid': illegal_sk, 'fld_id': 0 }).set_table_name(table_name)) self.write_multiple_request = WriteMultipleRequest().set_timeout( timeout) self.get_request = GetRequest().set_table_name(table_name) self.hour_in_milliseconds = 60 * 60 * 1000 self.day_in_milliseconds = 24 * 60 * 60 * 1000
def main(): handle = None try: # # Create a handle # handle = get_handle(tenant_id) # # Create a table # statement = 'Create table if not exists ' + table_name + '(id integer, \ sid integer, name string, primary key(shard(sid), id))' print('Creating table: ' + statement) request = TableRequest().set_statement(statement).set_table_limits( TableLimits(30, 10, 1)) handle.do_table_request(request, 50000, 3000) print('After create table') # # Put a few rows # request = PutRequest().set_table_name(table_name) for i in range(10): value = {'id': i, 'sid': 0, 'name': 'myname' + str(i)} request.set_value(value) handle.put(request) print('After put of 10 rows') # # Get the row # request = GetRequest().set_key({ 'id': 1, 'sid': 0 }).set_table_name(table_name) result = handle.get(request) print('After get: ' + str(result)) # # Query, using a range # statement = 'select * from ' + table_name + ' where id > 2 and id < 8' request = QueryRequest().set_statement(statement) print('Query results for: ' + statement) while True: result = handle.query(request) for r in result.get_results(): print('\t' + str(r)) if request.is_done(): break # # Delete the row # request = DeleteRequest().set_key({ 'id': 1, 'sid': 0 }).set_table_name(table_name) result = handle.delete(request) print('After delete: ' + str(result)) # # Get again to show deletion # request = GetRequest().set_key({ 'id': 1, 'sid': 0 }).set_table_name(table_name) result = handle.get(request) print('After get (should be None): ' + str(result)) # # Drop the table # if drop_table: request = TableRequest().set_statement('drop table if exists ' + table_name) handle.do_table_request(request, 40000, 2000) print('After drop table') else: print('Not dropping table') print('Example is complete') except Exception as e: print(e) traceback.print_exc() finally: # If the handle isn't closed Python will not exit properly if handle is not None: handle.close()
def setUp(self): TestBase.set_up(self) self.shardkeys = [0, 1] self.ids = [0, 1, 2, 3, 4, 5] self.rows = list() self.new_rows = list() self.versions = list() self.requests = list() self.illegal_requests = list() ttl = TimeToLive.of_days(16) for sk in self.shardkeys: self.rows.append(list()) self.new_rows.append(list()) self.versions.append(list()) for i in self.ids: row = {'fld_sid': sk, 'fld_id': i, 'fld_long': 2147483648, 'fld_float': 3.1414999961853027, 'fld_double': 3.1415, 'fld_bool': True, 'fld_str': '{"name": u1, "phone": null}', 'fld_bin': bytearray(pack('>i', 4)), 'fld_time': datetime.now(), 'fld_num': Decimal(5), 'fld_json': {'a': '1', 'b': None, 'c': '3'}, 'fld_arr': ['a', 'b', 'c'], 'fld_map': {'a': '1', 'b': '2', 'c': '3'}, 'fld_rec': {'fld_id': 1, 'fld_bool': False, 'fld_str': None}} new_row = deepcopy(row) new_row.update({'fld_long': 2147483649}) self.rows[sk].append(row) self.new_rows[sk].append(new_row) put_request = PutRequest().set_value(row).set_table_name( table_name).set_ttl(ttl) self.versions[sk].append( self.handle.put(put_request).get_version()) self.old_expect_expiration = ttl.to_expiration_time( int(round(time() * 1000))) self.ttl = TimeToLive.of_hours(1) self.ops_sk = 0 illegal_sk = 1 self.requests.append(PutRequest().set_value( self.new_rows[self.ops_sk][0]).set_table_name(table_name).set_ttl( self.ttl).set_return_row(True)) self.requests.append(PutRequest().set_value( self.new_rows[self.ops_sk][1]).set_table_name( table_name).set_option(PutOption.IF_ABSENT).set_ttl( self.ttl).set_return_row(True)) self.requests.append(PutRequest().set_value( self.new_rows[self.ops_sk][2]).set_use_table_default_ttl( True).set_table_name(table_name).set_option( PutOption.IF_PRESENT).set_return_row(True)) self.requests.append(PutRequest().set_value( self.new_rows[self.ops_sk][3]).set_table_name( table_name).set_option(PutOption.IF_VERSION).set_ttl( self.ttl).set_match_version( self.versions[self.ops_sk][3]).set_return_row(True)) self.requests.append(DeleteRequest().set_key( {'fld_sid': self.ops_sk, 'fld_id': 4}).set_table_name( table_name).set_return_row(True)) self.requests.append(DeleteRequest().set_key( {'fld_sid': self.ops_sk, 'fld_id': 5}).set_table_name( table_name).set_match_version( self.versions[self.ops_sk][0]).set_return_row(True)) self.illegal_requests.append(DeleteRequest().set_key( {'fld_sid': self.ops_sk, 'fld_id': 0}).set_table_name( 'IllegalUsers')) self.illegal_requests.append(DeleteRequest().set_key( {'fld_sid': illegal_sk, 'fld_id': 0}).set_table_name(table_name)) self.write_multiple_request = WriteMultipleRequest().set_timeout( timeout) self.get_request = GetRequest().set_table_name(table_name) self.hour_in_milliseconds = 60 * 60 * 1000 self.day_in_milliseconds = 24 * 60 * 60 * 1000
from borneo.iam import SignatureProvider from borneo import NoSQLHandleConfig, NoSQLHandle, Regions from borneo import DeleteRequest # create and close AuthorizationProvider at_provider = SignatureProvider(config_file='~/.oci/config') at_provider.close() # create handle config using a desired region as endpoint and set a # default compartment. handle_config = NoSQLHandleConfig(Regions.SA_SAOPAULO_1) handle_config.set_authorization_provider(at_provider) handle_config.set_default_compartment('<your-compartment-id>') # create the handle. nosql_handle = NoSQLHandle(handle_config) delete_request = DeleteRequest() delete_request.set_table_name('produtos') delete_request.set_key({"id": 1}) # delete data result = nosql_handle.delete(delete_request) if result.get_success(): print('Success!') else: print('Error!') # free up the resources from handle. nosql_handle.close()