Santiago de Diego
Santiago de Diego

Reputation: 305

Querying simple data in Hyperledger Composer

I have an structure defined like that:

concept Data
{
  o Double Temp
  o Double Hum
}


asset Reading identified by ReadingID
{
    o String ReadingID
    o String DeviceID
    o Integer Time
    o Data Data
}

In Composer, I can search for ReadingID without coding anything, because it is the "primary key" and this query is automatically defined.

However, if I want to retrieve all the assets trype "Reading" with the same DeviceID, I mean, making a query by using DeviceID, how can I do it? I was going through the tutorial but there is not an example of querying using basic types, like an String.

Upvotes: 0

Views: 40

Answers (1)

Paul O'Mahony
Paul O'Mahony

Reputation: 6740

correct, you can do exactly that - so, (for benefit of others 'reading' this) you could define a query in your queries.qry file:

eg

query selectReading {
  description: "my query"
  statement:
      SELECT org.acme.biznet.Reading
          WHERE (DeviceID ==_$device_id)
}


return query('selectReading', {device_id: device} )
// return query('selectReading', {device_id: '1234567'} )
        .then(function (results) {


           for (var n = 0; n < results.length; n++) {
            // process array of results
           }
       });

etc. And where device above is a var in your script file or etc.

Upvotes: 1

Related Questions