Loading TOC...

op:generate-view

op:generate-view(
   $schemaName as xs:string,
   $viewName as xs:string,
   [$columnDeclarations as map:map*]
) as element()

Summary

This method generates a view that encapsulates a query. Insert the generated XML into the schemas database and then use the op.fromView op:from-view accessor to use the generated view.

Parameters
$schemaName The schema name that can be passed to op:from-view() when accessing the generated view.
$viewName The view name that must be passed to op:from-view() when accessing the generated view.
$columnDeclarations Optional type and nullability declarations for some or all of the columns of the view.

Example

xquery version "1.0-ml";

import module namespace op="http://marklogic.com/optic"
     at "/MarkLogic/optic.xqy";

op:from-view("main", "employees")
   => op:where(cts:collection-query("/division/manufacturing"))
   => op:select(("EmployeeID", "FirstName", "LastName"))
   => op:order-by("EmployeeID")
   => op:generate-view("main", "manufacturingEmployees")
  

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.