view:create( $schema-name as xs:string, $name as xs:string, $scope as element(*,view:view-scope), $columns as element(view:column)*, $fields as element(view:field)*, $permissions as item()* ) as xs:unsignedLong
This function creates a new view in the specified schema specification. The id of the view is returned. The view is checked for validity.
Prior to executing this function, you must create a range index for each column in your view. For details on element range indexes, see Range Indexes and Lexicons in the Administrator's Guide.
Parameters | |
---|---|
schema-name | The name of the schema specification in which the view is created. |
name | The name of the view. The view name must be unique in the context of the schema in which it is created. A valid view name is a single word that starts with an alpha character. The view name may contain numeric characters, but cannot contain punctuation or special characters. |
scope |
The scope of the view used to constrain the subset of the database to which the view applies.
The scope can either limit rows in the view to documents with a specific element
(localname + namespace) or to documents in a particular collection. Use the
view:element-view-scope function to
set the scope to an element or the
view:collection-view-scope function to
set the scope to a collection.
For details on view scoping, see Defining View Scope in the SQL Data Modeling Guide. |
columns | A sequence of view columns. Each column has a name and a range index reference. |
fields | A sequence of view fields. Each field has a name and a field reference. |
permissions | The permissions required to access this view. When run in an XQuery context, the permissions are a sequence of XML elements (sec:permission). When importing this module into a Server-Side JavaScript context, the permissions are an array of Objects. |
xquery version "1.0-ml"; import module namespace view = "http://marklogic.com/xdmp/view" at "/MarkLogic/views.xqy"; view:create( "main", "songs", view:element-view-scope(xs:QName("SONG")), ( view:column("uri", cts:uri-reference()), view:column("title", cts:element-reference(xs:QName("TITLE"))), view:column("album", cts:element-reference(xs:QName("ALBUM"), ("nullable"))), view:column("year", cts:element-reference(xs:QName("YEAR"))) ), (), () ) (: Creates a view, named 'songs', of the 'main' schema that contains four columns, with a scope on the element, 'SONG'. :)