krupal.agile
krupal.agile

Reputation: 815

How to match string in query file in Hyperledger Composer?

I am facing one problem in this query statement: Query is returning no results.

query:

statement:
      SELECT org.example.identitynetwork.IdentityProof
          WHERE ((owner == _$owner) AND (proofName == _$proofName))

my cto is:

asset IdentityProof identified by proofId {
  o String proofId
  o String proofName
  o String encodedData
  --> Owner owner
}

In logic.js:

let idProofs = await query('selectRequestedIdProofsByOwner',
    {
        "owner": proofOwner,
        "proofName": proofName
    }
);

This query is returning no results even if I have permissions configured properly and there exists a proof with the given owner and proof name.

Upvotes: 0

Views: 78

Answers (1)

Mehul Prajapati
Mehul Prajapati

Reputation: 1260

use where and and filters,

let idProofs = await query('selectRequestedIdProofsByOwner',
    {
        "where": {
            "and": [
                { "owner": proofOwner },
                { "proofName": proofName }
            ]
        }
    }
);

Point to be noted, This does not work with relationship attributes, This is just for basic string matching. In your example owner matching with proofOwner won't work.

Update

Relationship matching can be done by prefixing namespace name with Resource type followed by # and Unique resource id.

let idProofs = await query('selectRequestedIdProofsByOwner',
    {
        "where": {
            "and": [
                { "owner": "resource:org.example.businessnetwoek.ParticipantType#"+proofOwner },
                { "proofName": proofName }
            ]
        }
    }
);

In your example uniqueId will be proofOwner

Upvotes: 1

Related Questions