2

I have tried to query Daml template text-Map it throwing me empty set instead of giving that particular data- for Example:

 "Data": [
            { "information":"XYZ",
        {
            "textMap": {
                "Type": {
                    "_1": "A",
                    "_2": "B"
                },
                "Date": {
                    "_1": "2019-11-29",
                    "_2": "AMD"
                },
                }
            }
        }}
    ]

here,in the above sample i tried to query only using type key but it is not throwing any data related to that particular key,but when i sending both key values of Map i can able to get that particular data.but i want to send only one key value inside of that Map for querying it.how can achieve this in daml.

arjun a
  • 151
  • 7

1 Answers1

3

TextMap behaves similar to lists in the query API. A map is a value, which you can match on as a whole only. You can see the behaviour for lists here.

Suppose you have a simple TextMap in a template:

daml 1.2
module Main where

import DA.TextMap as Map

template T
  with
    p : Party
    m : TextMap Int
  where
    signatory p

setup = scenario do
  p <- getParty "p"
  submit p do
    create T with
      p
      m = Map.fromList [
          ("one", 1),
          ("two", 2)
        ]

The call to contracts/search with the below payload will match.

{ 
  "%templates": [ 
    { 
      "moduleName": "Main", 
      "entityName": "T" 
    } 
  ], 
  "m" : {
    "two": "2", 
    "one": "1"
  } 
}

Even though the order of the map items is switched around, the argument for m represents the same map, so the values are equal.

However, changing to simply "m" : { "one" : "1" } will not match. We are querying for a contract of type T with a map with only one entry "one".

There are currently no query options for "containsKey" or "contains".

bame
  • 960
  • 5
  • 7