Skip to content
CCPEDIAby Unity Nodes
App Development

Typescript date filtering on useQuery or StreamQuery

4 posts472 views3 likesLast activity Feb 2022

  1. Joao_FreitasOP

    Hello everyone

    I am using the useQuery hook and I am trying to filter by a date range.

    const { contracts: historyContracts, loading: loadingContracts } =
            useStreamQueries(
                SomeContract,
                () => {
                    return [
                        {
                            customer: party,
                            date: from 1980-01-01 to 2022-01-01
                        }
                    ]
                },
                [party,]
            )
    

    How can I use the JSON api query language applied to the hooks (useQuery or useStreamQueries)? Thank you in advance
    https://docs.daml.com/json-api/search-query-language.html#comparison-query

  2. Max 1

    useStreamQueries is from the @daml/react library, and from the docs, says it can only accept {field: value}, so really you can only query a specific date, and not a range I think.

    If you need to query the range, it seems that you shouldn’t be using the hooks from the daml/react library, but rather explicitly create a GET request from your frontend.

  3. Gary_Verhaegen 2

    I don’t think the code of useStreamQueries adds any restriction, but if you’re using TypeScript it’s possible that the types do. I haven’t looked at the React bindings in a while, but I do remember it was pretty hard to express the full query language in TypeScript.

    For the query language itself, though, the syntax for what you want would be:

    const { contracts: historyContracts, loading: loadingContracts } =
            useStreamQueries(
                SomeContract,
                () => {
                    return [
                        {
                            customer: party,
                            date: { "%gte": "1980-01-01", "%lte": "2022-01-01" }
                        }
                    ]
                },
                [party,]
            )
    
  4. Leonid_Rozenberg

    @Gary_Verhaegen 's favorite issue! :troll: Please add support for the comparison language to the Typescript libraries. · Issue #7656 · digital-asset/daml · GitHub