MarkLogic Server 11.0 Product Documentation
op.fromParam

op.fromParam(
   paramName as String,
   qualifier as String?,
   rowColTypes as Object[]
) as ModifyPlan

Summary

This function constructs document rows with rows provided by a parameter.

Parameters
paramName The paramName parameter specifies the placeholder parameter supplying the rows.
qualifier Specifies a name for qualifying the column names.
rowColTypes Describes the columns with an array of JavaScript objects. It's a combinations of column, type and nullable. The 'column' is the column name, which is required. The 'type' is the optional type of the column, which can be an atomic type or the default of none. The 'nullable' is an optional boolean defaulting to false. If your rows contains only uri, doc, collections, metadata, permissions, quality and temporalCollection columns, you could simply use op.docColTypes instead.

See Also

Example

// It returns
// {"qualifier1.id":1, "qualifier1.firstName":"Jane", "qualifier1.lastName":"Woods"}
// {"qualifier1.id":2, "qualifier1.firstName":"Ken", "qualifier1.lastName":"First"}
const op = require('/MarkLogic/optic');
const rows =
  [{id: 1, firstName: 'Jane', lastName: 'Woods'},
   {id: 2, firstName: 'Ken', lastName: 'First'}];
const columnTypes   = [
      {"column":"id",        "type":"integer", "nullable":false},
      {"column":"firstName", "type":"string",  "nullable":true},
      {"column":"lastName",  "type":"string",  "nullable":true}];
op.fromParam("param", "qualifier1", columnTypes)
  .result("object", {"param":rows});
  

Example

/* It returns
 [{"left.collections":null,
 "right.val":0,
 "left.doc":{"desc":"test0"},
 "right.uri":"/test/0.json",
 "left.metadata":null,
 "left.permissions":null,
 "left.quality":null,
 "left.temporalCollection":null,
 "left.uri":"/test/0.json"},
 {"left.collections":null,
 "right.val":5,
 "left.doc":{"desc":"test5"},
 "right.uri":"/test/5.json",
 "left.metadata":null,
 "left.permissions":null,
 "left.quality":null,
 "left.temporalCollection":null,
 "left.uri":"/test/5.json"}]
*/

const op = require('/MarkLogic/optic');
const rows = [
    {uri:'/test/0.json', doc:{"desc":"test0"}},
    {uri:'/test/1.json', doc:{"desc":"test1"}},
    {uri:'/test/5.json', doc:{"desc":"test5"}}];
const fromParam = op.fromParam('param', 'left', op.docColTypes())
const fromLiteral = op.fromLiterals([
            {uri:'/test/0.json', val:0},
            {uri:'/test/5.json', val:5}
            ], 'right')
fromParam
  .joinInner(fromLiteral)
  .where(
      op.eq(
           op.viewCol('left', 'uri'),
           fromLiteral.col('uri')
           )
      )
  .result('object', {'param':rows});
  
Powered by MarkLogic Server | Terms of Use | Privacy Policy