You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Hyperledger Fabric Composer查询建模:如何传递多参数替代IN操作符

Workarounds for Hyperledger Query Language Without IN Operator

Got it, since Hyperledger's query language doesn't support the IN operator yet, here are a few practical workarounds to help you select claims by multiple transaction IDs:

  • Dynamic OR Condition Chain
    Logically, IN (val1, val2, val3) is equivalent to transactionId = val1 OR transactionId = val2 OR transactionId = val3. You can dynamically build your query statement with multiple OR clauses to match each transaction ID in your array.

    For example, if you have three transaction IDs to filter, your query would look like this:

    query selectClaimsByMultipleTransactionID{
      description: "Select all claims based on TransactionID"
      statement: SELECT bbc.example.biznet WHERE (transactionId = _$txId1 OR transactionId = _$txId2 OR transactionId = _$txId3)
    }
    

    In your application code, loop through your transaction ID array to construct the WHERE clause programmatically—add a new OR transactionId = _$txIdN segment for each entry. Just remember to pass each individual parameter when executing the query.

  • Index Asset for Lookup
    If your workflow allows pre-processing, create a dedicated index asset that maps transaction IDs to their corresponding claim IDs. For example:

    {
      "$class": "bbc.example.TransactionClaimIndex",
      "transactionId": "tx-123",
      "claimIds": ["claim-456", "claim-789"]
    }
    

    First, query all index assets matching your target transaction IDs, collect all associated claim IDs, then run a second query to fetch the full claim details using those IDs. This works great if you can maintain this index whenever a new claim is created.

  • CouchDB Rich Queries (If Using CouchDB as State DB)
    If your Hyperledger Fabric network uses CouchDB as the state database, you can use CouchDB's native JSON query syntax directly in your chaincode—this natively supports the $in operator.

    Here's a Node.js chaincode example:

    const query = {
      selector: {
        transactionId: { $in: ["tx-123", "tx-456", "tx-789"] }
      }
    };
    const result = await this.stub.getQueryResult(JSON.stringify(query));
    

    This gives you full access to CouchDB's query features, but note it only works if you're using CouchDB (not LevelDB).

内容的提问来源于stack exchange,提问作者Raj_Shekhar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 06:34:14