We are exploring Optic API and doing some POCs also to replace our existing code with Optic API query.
As part of our new requirement, we want to use optic-fn, optic-json, optic-xdmp, optic-xs, we spent so much time finding examples or sample code using optic-fn, optic-json, optic-xdmp, optic-xs but we could not find any sample code for reference.
Could anyone help us to give a sample code snippet for each(optic-fn, optic-json, optic-xdmp, optic-xs) so it will be very helpful for us?
Any help is appreciated.
In XQuery, you import not only the core Optic library
but also the libraries that provide any expression functions that needed in the query. Use any combination of the following libraries:
Thereafter, you call the functions in the same way with the important difference that the arguments can include not only literals but
op:col("NAME")
to specify column values or the return values from other, nested expression functions as in:Note that you only use the functions from the Optic expression libraries when operating on values during execution of the query. To operate on literal values passed as arguments when building the plan, use the ordinary functions.
In particular, cts:query() arguments are always constructed in the
cts
namespace and not theocts
namespace.For details about what functions are exposed as expression functions and about how expression functions are exposed in SJS, see also: https://stackoverflow.com/a/65924267/1091497
Hoping that helps,