|
|
view:create(
|
|
$schema-name as xs:string,
|
|
$name as xs:string,
|
|
$scope as element(*,view:view-scope),
|
|
$columns as element(view:column)*,
|
|
$permissions as element(sec:permission)*
|
| ) as xs:unsignedLong |
|
 |
Summary:
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.
|
$permissions
:
The permissions required to access this view.
|
|
Example:
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'. :)
|
|
|
|
view:set-columns(
|
|
$schema-name as xs:string,
|
|
$view-name as xs:string,
|
|
$columns as element(view:column)*
|
| ) as empty-sequence() |
|
 |
Summary:
This function replaces the current set of column specifications on the named
view in the named schema with a new set of columns.
|
Parameters:
$schema-name
:
The name of the schema specification containing the view.
|
$view-name
:
The name of the view containing the column specifications to be reset.
|
$columns
:
A sequence of column specifications for the view.
|
|
Example:
xquery version "1.0-ml";
import module namespace view = "http://marklogic.com/xdmp/view"
at "/MarkLogic/views.xqy";
view:set-columns("main", "songs",
( view:column("uri", cts:uri-reference()),
view:column("title", cts:element-reference(xs:QName("TITLE"))),
view:column("author", cts:element-reference(xs:QName("AUTHOR"))),
view:column("album", cts:element-reference(xs:QName("ALBUM"), ("nullable"))),
view:column("year", cts:element-reference(xs:QName("YEAR"))) ) )
(: Sets five columns in the 'songs' view in the 'main' schema. :)
|
|
|