Hi Rob,
may I ask what you intented to do? Looks like you expect $dataRec to contain exactly one value, right?
At least I think so because you called `db:create#1` in `fn:apply` which implies you expect the array to contain a single value.
To create a single database use:
```
db:create($dataRec => array:get(1))
```
…or… if you want to create a database for each of the array values:
for $db in ($dataRec => array:flatten()) (: Flatten array to a sequence :)
return db:create($db). (: create one database per array item :)
…and… last but not least, for "Dynamic Updating Function Invocation“[1] you might use:
let $create := db:create#1
for $db in ($dataRec => array:flatten())
return invoke updating $create($db)
I could not wrap my head around using array:for-each(#2) and dynamic updating function invocation; this could make for a more readable solution, but I can not seem to get the syntax right; if we already fully support it at all ;-)
I hope I did not get you all wrong, feel free to ask for more help! ;-)
Best
Michael
Hi,
I want to use the apply function within an updating webfunction, see[1]
How can this be done?
TIA,
Rob Stapper
[1]
declare
%rest:path("/cFactBank/dbCreate")
%rest:PUT("{$dataRec}")
%input:json("format=map")
%updating
function _:cFactBank.dbCreate
( $dataRec as array(*)
)
{
apply( db:create#1
, $dataRec
)
} ;