Skip to content

Commit e1b71d2

Browse files
added queryAllByKey (#22738)
1 parent 17f4198 commit e1b71d2

File tree

9 files changed

+81
-39
lines changed

9 files changed

+81
-39
lines changed

sdk/compiler/damlc/daml-preprocessor/src/DA/Daml/Preprocessor.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ preprocessorExceptions = Set.fromList $ map GHC.mkModuleName
7878
, "DA.Exception.AssertionFailed"
7979
, "DA.Exception.PreconditionFailed"
8080
, "DA.Fail"
81+
, "DA.ContractKeys"
8182

8283

8384
-- These modules need to have the record preprocessor disabled.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- Copyright (c) 2025 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2+
-- SPDX-License-Identifier: Apache-2.0
3+
4+
{-# LANGUAGE CPP #-}
5+
6+
-- | Note: Docs TODO (https://github.com/digital-asset/daml/issues/22673)
7+
module DA.ContractKeys where
8+
9+
#ifdef DAML_NUCK
10+
import DA.Internal.Template.Functions as DA
11+
12+
queryNByKey : forall t k. HasQueryNByKey t k => Int -> k -> Update [(ContractId t, t)]
13+
queryNByKey = DA.queryNByKey
14+
15+
queryAllByKey : forall t k. HasQueryNByKey t k => k -> Update [(ContractId t, t)]
16+
queryAllByKey = DA.queryNByKey (maxBound @Int)
17+
#endif

sdk/compiler/damlc/daml-stdlib-src/LibraryModules.daml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import DA.Action.State
1313
import DA.Assert
1414
import DA.BigNumeric
1515
import DA.Bifunctor
16+
import DA.ContractKeys
1617
import DA.Crypto.Text
1718
import DA.Date
1819
import DA.Either

sdk/compiler/damlc/daml-stdlib-src/Prelude.daml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import DA.Internal.LF as X hiding
1818
-- but we can hide them.
1919
import DA.Internal.Any as X
2020
import DA.Internal.Template as X
21-
import DA.Internal.Template.Functions as X
21+
import DA.Internal.Template.Functions as X hiding (queryNByKey)
2222
import DA.Internal.Compatible as X
2323
import DA.Internal.Assert as X
2424
import DA.Internal.Interface as X

sdk/compiler/damlc/tests/daml-test-files/QueryNByKey.daml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
module QueryNByKey where
77

8-
-- import Daml.Script
8+
import DA.ContractKeys
99

1010
template WithKey
1111
with
@@ -20,17 +20,26 @@ template Helper
2020
p : Party
2121
where
2222
signatory p
23-
choice PerformQuery : ()
23+
choice PerformQueryNByKey : ()
2424
controller p
2525
do contracts <- queryNByKey @WithKey 1 p
2626
case contracts of
2727
(contract :: _) -> do
2828
pure ()
2929
[] ->
3030
abort "Assertion failed: queryNByKey returned an empty list."
31+
choice PerformQueryAllByKey : ()
32+
controller p
33+
do contracts <- queryAllByKey @WithKey p
34+
case contracts of
35+
(contract :: _) -> do
36+
pure ()
37+
[] ->
38+
abort "Assertion failed: queryAllByKey returned an empty list."
3139

3240
-- Test just here to assert that queryNByKey compiles
3341
-- When we have an ledger implementation, assert things actually run
3442
-- test = script do
3543
-- p <- allocateParty "p"
36-
-- submit p $ createAndExerciseCmd (Helper p) PerformQuery
44+
-- submit p $ createAndExerciseCmd (Helper p) PerformQueryNByKey
45+
-- submit p $ createAndExerciseCmd (Helper p) PerformQueryAllByKey

sdk/compiler/damlc/tests/platform-independence.dar-hash

Lines changed: 35 additions & 35 deletions
Large diffs are not rendered by default.

sdk/docs/sharable/hoogle/daml-base-hoogle.txt

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/docs/sharable/sdk/reference/daml/stdlib/DA-ContractKeys.rst

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/docs/sharable/sdk/reference/daml/stdlib/index.rst

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)