crazyPen
crazyPen

Reputation: 873

Syntax for passing two values into a query for hyperledger fabric?

I have this hyperledger composer query where two values are passed in _$option and _$trader.

query selectCallPositionForSeller {
  description: "Select call position based on ID"
  statement:
        SELECT org.tradenetwork.Trader
          WHERE (callPosition.option == _$option AND user_id == _$trader )
}

Where callPosition is an array of concepts. That I am trying to call like this.

const selectByContract = await query('selectCallPositionForSeller', {'option': option}, {'trader': seller});

But I believe this syntax is incorrect. What is the correct syntax for passing two values?

Also is user_id = _$trader the correct way to compare objects?

And does hyperledger fabric allow for a variable number of arguments? (which is what I have assumed in my query).

Upvotes: 0

Views: 328

Answers (2)

crazyPen
crazyPen

Reputation: 873

Thought I'd post an answer to this since the other answer isn't 100% correct and this might be helpful for someone.

Here's the query (callposition is a concept)

query selectSellerByContractAndCall {
  description: "Select call position based on seller ID"
  statement:
        SELECT org.mining3.tradenetwork.Trader
          WHERE ((callPosition CONTAINS (option == _$option)) AND (user_id == _$seller))
}

And it is called like this

const selectSellerByContractAndCall = await query('selectSellerByContractAndCall', 
    {'option': 'resource:org.mining3.tradenetwork.Option#' + option.optionId, 'seller': seller.user_id });

This is the correct way to pass an object (i.e. option) into the query. Which can have logic on it like this.

for(cp of selectSellerByContractAndCall[0].callPosition){
    //logic here
}

Upvotes: 1

Unai
Unai

Reputation: 11

I think that your syntax is incorrect. Try calling like this:

return query('selectCallPositionForSeller', { "option": option, "trader": seller})

And, just in case, put the select like this:

query selectCallPositionForSeller {
description: "Select call position based on ID"
statement:
    SELECT org.tradenetwork.Trader
      WHERE ((callPosition.option == _$option) AND (user_id == _$trader))
}

hope this help!

Upvotes: 1

Related Questions