Using Get API to fetch data

Use the GetRequest API to fetch a single row of data using the primary key.

By default, all read operations are eventually consistent. This type of read is less costly than those using absolute consistency. You can change the default Consistency for a NoSQLHandle instance by using the setConsistency() method in the Consistency class.

The GetRequest class provides a simple and powerful way to read data, while queries can be used for more complex read requests. To read data from a table, specify the target table and target key using the GetRequest class and use NoSQLHandle.get() to execute your request. The result of the operation is available in GetResult. You can change the default Consistency for a NoSQLHandle instance by using the NoSQLHandleConfig.setConsistency(oracle.nosql.driver.Consistency) and GetRequest.setConsistency() methods.

Download the full code QueryData.java from the examples here.
//Fetch single row using get API
private static void getRow(NoSQLHandle handle,String colName,int Id) throws Exception {
   MapValue key = new MapValue().put(colName, Id);
   GetRequest getRequest = new GetRequest().setKey(key)
                                        .setTableName(tableName);
   GetResult getRes = handle.get(getRequest);
   /* on success, GetResult.getValue() returns a non-null value */
   if (getRes.getValue() != null) {
      System.out.println("\t" +getRes.getValue().toString());
   } else {
      System.out.println("Get Failed");
   }
}

Note:

To fetch data from a child table, specify the full name of the table (parent_tablename.child_tablename) in the setTableName method. Download the full code TableJoins.java from the examples to understand how to fetch data from a parent-child table here.

Use the GetRequest API to fetch a single row of data using the primary key. You can read single rows using the borneo.NoSQLHandle.get() method. This method allows you to retrieve a record based on its primary key value. The borneo.GetRequest class is used for simple get operations. It contains the primary key value for the target row and returns an instance of borneo.GetResult. You can change the default Consistency for a borneo.NoSQLHandle using borneo.NoSQLHandleConfig.set_consistency() before creating the handle. It can be changed for a single request using borneo.GetRequest.set_consistency().

Download the full code QueryData.py from the examples here.
# Fetch single row using get API
def getRow(handle,colName,Id):
  request = GetRequest().set_table_name('stream_acct')
  request.set_key({colName: Id})
  print('Query results: ')
  result = handle.get(request)
  print('Query results are' + str(result.get_value()))

Note:

To fetch data from a child table, specify the full name of the table (parent_tablename.child_tablename) in the set_table_name method. Download the full code TableJoins.py from the examples to understand how to fetch data from a parent-child table here.

Use the GetRequest API to fetch a single row of data using the primary key. You can read single rows using the Client.Get function. This function allows you to retrieve a record based on its primary key value. The nosqldb.GetRequest is used for simple get operations. It contains the primary key value for the target row and returns an instance of nosqldb.GetResult. If the get operation succeeds, a non-nil GetResult.Version is returned. You can change the default Consistency for a nosqldb.RequestConfig using RequestConfig.Consistency before creating the client. It can be changed for a single request using GetRequest.Consistency field.

Download the full code QueryData.go from the examples here.
//fetch data from the table
func getRow(client *nosqldb.Client, err error, tableName string, colName string, Id int)(){
	key:=&types.MapValue{}
   key.Put(colName, Id)
   req:=&nosqldb.GetRequest{
         TableName: tableName,
         Key: key,
   }
   res, err:=client.Get(req)
   if err != nil {
      fmt.Printf("GetResults() failed: %v\n", err)
      return
   }
   if res.RowExists() {
      fmt.Printf("Got row: %v\n", res.ValueAsJSON())
   } else {
      fmt.Printf("The row does not exist.\n")
   }
}

Note:

To fetch data from a child table, specify the full name of the table (parent_tablename.child_tablename) in the TableName parameter. Download the full code TableJoins.go from the examples to understand how to fetch data from a parent-child table here.

Use the get API to fetch a single row of data using the primary key. You can read a single row using the get method. This method allows you to retrieve a record based on its primary key value. For method details, see NoSQLClient class.

Set the consistency of the read operation using Consistency enumeration. You can set the default Consistency for read operations in the initial configuration that is used to create a NoSQLClient instance using the consistency property. You can also change it for a single read operation by setting the consistency property in the GetOpt argument of the get method.

JavaScript: Download the full code QueryData.js from the examples here.
//fetches single row with get API
async function getRow(handle,idVal) {
   try {
      const result = await handle.get(TABLE_NAME,{acct_Id: idVal });
      console.log('Got row:  %O', result.row);
   } catch(error) {
      console.error('  Error: ' + error.message);
   }
}
TypeScript: You can also supply an optional type parameter for a row to get and other data-related methods. The type parameter allows the TypeScript compiler to provide type hints for the returned GetResult method, as well as type-check the passed key. While type checking, the compiler inspects if the primary key field is a part of the table schema and if the type of the primary key field is one of the allowed types, that is either string, numeric, date or boolean. Download the full code QueryData.ts from the examples here.
interface StreamInt {
   acct_Id: Integer;
   profile_name: String;
   account_expiry: TIMESTAMP;
   acct_data: JSON;
}
/*fetches single row with get API*/
async function getRow(handle: NoSQLClient,idVal: Integer) {
   try {
      const result = await handle.get<StreamInt>(TABLE_NAME,{acct_Id: idVal });
      console.log('Got row:  %O', result.row);
   } catch(error) {
      console.error('  Error: ' + error.message);
   }
}

Note:

To fetch data from a child table, specify the full name of the table (parent_tablename.child_tablename) in the TABLE_NAME parameter. Download the full JavaScript code TableJoins.js here and the full TypeScript code TableJoins.ts here to understand how to fetch data from a parent-child table.

Use the GET API to fetch a single row of data using the primary key. You can read a single row using the GetAsync method. This method allows you to retrieve a row based on its primary key value. The field names should be the same as the table primary key column names. You may also pass options as GetOptions.

You can set consistency of a read operation using Consistency enumeration. The default consistency for read operations may be set as Consistency property of NoSQLConfig. You may also change the consistency for a single Get operation by using Consistency property of GetOptions. GetAsync method returns Task<GetResult<RecordValue>>. GetResult instance contains the returned Row, the row Version and other information. If the row with the provided primary key does not exist in the table, the values of both Row and Version properties will be null.

Download the full code QueryData.cs from the examples here.
private static async Task getRow(NoSQLClient client,String colName, int Id){
   var result = await client.GetAsync(TableName,
         new MapValue
         {
             [colName] =Id
         });
   if (result.Row != null){
      Console.WriteLine("Got row: {0}\n", result.Row.ToJsonString());
   }
   else {
      Console.WriteLine("Row with primaryKey {0} doesn't exist",colName);
   }
}

Note:

To fetch data from a child table, specify the full name of the table (parent_tablename.child_tablename) in the TableName parameter. Download the full code TableJoins.cs from the examples to understand how to fetch data from a parent-child table here.