APIの使用によるデータの更新

問合せリクエストでUPDATE SQLコマンドを使用して、データを更新できます。

問合せを実行するには、NoSQLHandle.query() APIを使用します。

こちらにあるサンプルの中からフル・コードModifyData.javaをダウンロードします。
//Update data
private static void updateRows(NoSQLHandle handle,String sqlstmt) throws Exception {
   QueryRequest queryRequest = new QueryRequest().setStatement(sqlstmt);
   handle.query(queryRequest);
   System.out.println("Updated table " + tableName);
}
/* update non-JSON data*/
String upd_stmt ="UPDATE stream_acct SET account_expiry=\"2023-12-28T00:00:00.0Z\" WHERE acct_Id=3";
updateRows(handle,upd_stmt);

問合せを実行するには、borneo.NoSQLHandle.query()メソッドを使用します。

こちらにあるサンプルの中からフル・コードModifyData.pyをダウンロードします。
#update data
def update_data(handle,sqlstmt):
   request = QueryRequest().set_statement(sqlstmt)
   result = handle.query(request)
   print('Data Updated in table: stream_acct')
# update non-JSON data
upd_stmt ='''UPDATE stream_acct SET account_expiry="2023-12-28T00:00:00.0Z" WHERE acct_Id=3'''
update_data(handle,upd_stmt)

問合せを実行するには、Client.Query関数を使用します。

こちらにあるサンプルの中からフル・コードModifyData.goをダウンロードします。
//update data in the table
func updateRows(client *nosqldb.Client, err error, tableName string, querystmt string)(){
   prepReq := &nosqldb.PrepareRequest{
		Statement: querystmt,
   }
   prepRes, err := client.Prepare(prepReq)
   if err != nil {
      fmt.Printf("Prepare failed: %v\n", err)
      return
   }
   queryReq := &nosqldb.QueryRequest{
      PreparedStatement: &prepRes.PreparedStatement,   }
      var results []*types.MapValue
      for {
         queryRes, err := client.Query(queryReq)
  	if err != nil {
     	fmt.Printf("Upsert failed: %v\n", err)
     	return
  	}
  	res, err := queryRes.GetResults()
  	if err != nil {
     	fmt.Printf("GetResults() failed: %v\n", err)
     	return
  	}
  	results = append(results, res...)
  	if queryReq.IsDone() {
     	break
  	}
     }  
     for i, r := range results {
        fmt.Printf("\t%d: %s\n", i+1, jsonutil.AsJSON(r.Map()))
     }
     fmt.Printf("Updated data in the table: \n")
}
updt_stmt := "UPDATE stream_acct SET account_expiry='2023-12-28T00:00:00.0Z' WHERE acct_Id=3"
updateRows(client, err,tableName,updt_stmt)

問合せを実行するには、queryメソッドを使用します。

JavaScript: こちらにあるサンプルの中からフル・コードModifyData.jsをダウンロードします。
/*updates data in the table*/
async function updateData(handle,querystmt) {
   const opt = {};
   try {
      do {
         const result = await handle.query(querystmt, opt);
         opt.continuationKey = result.continuationKey;
      } while(opt.continuationKey);
   } catch(error) {
      console.error('  Error: ' + error.message);
   }
}
TypeScript: こちらにあるサンプルの中からフル・コードModifyData.tsをダウンロードします。
interface StreamInt {
   acct_Id: Integer;
   profile_name: String;
   account_expiry: TIMESTAMP;
   acct_data: JSON;
}
async function updateData(handle: NoSQLClient,querystmt: string) {
   const opt = {};
   try {
      do {
         const result = await handle.query<StreamInt>(querystmt, opt);
         for(let row of result.rows) {
            console.log('  %O', row);
         }
         opt.continuationKey = result.continuationKey;
      } while(opt.continuationKey);
   } catch(error) {
      console.error('  Error: ' + error.message);
   }
}
const updt_stmt = 'UPDATE stream_acct SET account_expiry="2023-12-28T00:00:00.0Z" WHERE acct_Id=3'

await updateData(handle,updt_stmt);
console.log("Data updated in the table");

問合せリクエストでUPDATE SQLコマンドを使用して、データを更新できます。問合せを実行するには、QueryAsyncメソッドをコールするか、GetQueryAsyncEnumerableメソッドをコールして、結果の非同期列挙可能性に対して反復処理します。

こちらにあるサンプルの中からフル・コードModifyData.csをダウンロードします。
private static async Task updateData(NoSQLClient client,String querystmt){
   var queryEnumerable = client.GetQueryAsyncEnumerable(querystmt);
}
private const string updt_stmt = 
@"UPDATE stream_acct SET account_expiry =""2023-12-28T00:00:00.0Z"" WHERE acct_Id=3";

await updateData(client,updt_stmt);
Console.WriteLine("Data updated in the table");