Using API to delete a single row

You can use the DeleteRequest API and delete a single row using a primary key.

The DeleteRequest API can be used to perform unconditional and conditional deletes.
  • Delete any existing row. This is the default.
  • Succeed only if the row exists and its version matches a specific version. Use setMatchVersion for this case.
Download the full code ModifyData.java from the examples here.
//delete row based on primary KEY
private static void delRow(NoSQLHandle handle, MapValue m1) throws Exception {
   DeleteRequest delRequest = new DeleteRequest().setKey(m1).setTableName(tableName);
   DeleteResult del = handle.delete(delRequest);
   if (del.getSuccess()) {
     System.out.println("Delete succeed");
   }
   else {
     System.out.println("Delete failed");
   }
}
/*delete a single row*/
MapValue m1= new MapValue();
m1.put("acct_Id",1);
delRow(handle,m1);

Single rows are deleted using borneo.DeleteRequest using a primary key value.

Download the full code ModifyData.py from the examples here.
#del row with a primary KEY
def del_row(handle,table_name):
   request = DeleteRequest().set_key({'acct_Id': 1}).set_table_name(table_name)
   result = handle.delete(request)
   print('Deleted data from table: stream_acct')
# delete row based on primary key
del_row(handle,'stream_acct')

The DeleteRequest is used to delete a row from a table. The row is identified using a primary key specified in DeleteRequest.Key.

Download the full code ModifyData.go from the examples here.
//delete with primary key
func delRow(client *nosqldb.Client, err error, tableName string)(){
   key := &types.MapValue{}
   key.Put("acct_Id",1)
   delReq := &nosqldb.DeleteRequest{
   	TableName: tableName,
   	Key:       key,
   }
   delRes, err := client.Delete(delReq)
   if err != nil {
	fmt.Printf("failed to delete a row: %v", err)
	return
   }
   if delRes.Success {
	fmt.Println("Delete succeeded")
   }
}
delRow(client, err,tableName)

Use the delete method to delete a row from a table. For method details, see NoSQLClient class.

You must pass the table name and primary key of the row. In addition, you can make the delete operation conditional by specifying a RowVersion of the row that was previously returned by get or put methods.

JavaScript: Download the full code ModifyData.js from the examples here.
/*delete row based on primary key*/
async function delRow(handle) {
   try {
      /* Unconditional delete, should succeed.*/
      var result = await handle.delete(TABLE_NAME, { acct_Id: 1 });
      /* Expected output: delete succeeded*/
      console.log('delete ' + result.success ? 'succeeded' : 'failed');
   } catch(error) {
      console.error('  Error: ' + error.message);
   }
}
await delRow(handle);
console.log("Row deleted based on primary key");
TypeScript: Download the full code ModifyData.ts from the examples here.
interface StreamInt {
   acct_Id: Integer;
   profile_name: String;
   account_expiry: TIMESTAMP;
   acct_data: JSON;
}
/*delete row based on primary key*/
async function delRow(handle: NoSQLClient) {
   try {
      /* Unconditional delete, should succeed.*/
      var result = await handle.delete<StreamInt>(TABLE_NAME, { acct_Id: 1 });
      /* Expected output: delete succeeded*/
      console.log('delete ' + result.success ? 'succeeded' : 'failed');
   } catch(error) {
      console.error('  Error: ' + error.message);
   }
}
await delRow(handle);
console.log("Row deleted based on primary key");

To delete a row, use DeleteAsync method. Pass to it the table name and primary key of the row to delete. This method takes the primary key as MapValue. The field names should be the same as the table primary key column names.

DeleteAsync and DeleteIfVersionAsync methods return Task<DeleteResult<RecordValue>>. DeleteResult instance contains success status of the Delete operation. Delete operation may fail if the row with given primary key does not exist or this is a conditional Delete and provided row version did not match the existing row version.

Download the full code ModifyData.cs from the examples here.
private static async Task delRow(NoSQLClient client){
   var primaryKey = new MapValue
   {
      ["acct_Id"] = 1
   };
   // Unconditional delete, should succeed.
   var deleteResult = await client.DeleteAsync(TableName, primaryKey);
   // Expected output: Delete succeeded.
   Console.WriteLine("Delete {0}.",deleteResult.Success ? "succeeded" : "failed");
}
await delRow(client);
Console.WriteLine("Row deleted based on primary key");