This page was generated
January  28,  2016
4:08  AM
XQuery & XSLT Built-In & Modules Function Reference

Module: Views

The views module is used to create and manage SQL schemas and views.

A schema defines a logical scoping for views. A schema has a unique id, a name (which must also be unique), and a collection of views. During SQL execution, the schema provides the naming context for its views, which enables you have have multiple views of the same name in different schemas. The default schema is called "main". Even though it is a default, you must create the "main" schema before it can be used.

A view is an abstraction of a SQL "table." However, unlike in a relational database, a view in MarkLogic server is implemented on top of element range indexes. A view consists of a unique id, a name (which must be unique in the context of a particular schema), a view scope, and a sequence of column specifications. Each column has a name and a range index reference. The range index for each column must be created before creating the view. The view scope is used to constrain the subset of the database to which the view applies. The view scope can either limit rows in the view to documents with a specific element (localname + namespace) or to documents in a particular collection.

The views function module is installed as the following file:

  • install_dir/Modules/MarkLogic/views.xqy

where install_dir is the directory in which MarkLogic Server is installed.

To use the views.xqy module in your own XQuery modules, include the following line in your XQuery prolog:

import module namespace view="http://marklogic.com/xdmp/view" at "/MarkLogic/views.xqy";

You must have the view-admin role to execute the functions in the View library.

Function Summary
view:add-column This function adds column specifications to the current set of column specifications on the named view in the named schema.
view:add-field This function adds a field to the named view.
view:add-permissions This function adds permissions to those already set for the named view in the named schema specification.
view:collection This function return the URI of the protected collection holding all the views.
view:collection-view-scope This function constructs a new collection-style view scope specification.
view:column This function constructs a new column specification.
view:columns This function returns the sequence of column specifications set in the named view in the named schema.
view:create This function creates a new view in the specified schema specification.
view:element-view-scope This function constructs a new element-style view scope specification.
view:field This function constructs a new element-style field specification for the named field.
view:fields This function returns the fields set on the named view.
view:get This function returns the named view from the named schema specification.
view:get-bindings This function generates a binding map suitable for use with cts:parse from the named view.
view:get-by-id This function returns the view with the specified id.
view:get-column This function returns the named column specification set in the named view in the named schema.
view:get-field This function returns the element specification for the named field.
view:get-permissions This function returns the permissions set on the specified view.
view:get-view-scope This function returns the scope of the named view in the named schema.
view:remove This function removes the named view from the named schema specification.
view:remove-by-id This function removes the view with the specified id.
view:remove-column This function removes a column specification from the named view in the named schema.
view:remove-field This function removes a field from the named view.
view:remove-permissions This function removes permissions from those set for the named view in the named schema specification.
view:schema-add-permissions This function adds permissions to the specified schema specification.
view:schema-create This function creates a new relational schema in the Schema database.
view:schema-get This function returns the named schema specification document.
view:schema-get-permissions This function returns the permissions set on the specified schema.
view:schema-remove This function removes the specified schema.
view:schema-remove-permissions This function removes permissions from the specified schema specification.
view:schema-set-permissions This function sets permissions on the specified schema specification.
view:schemas This function returns all of the schema specifications.
view:set-columns This function replaces the current set of column specifications on the named view in the named schema with a new set of columns.
view:set-fields This function sets the specified fields on the specified view.
view:set-name This function renames the named view in the named schema specification.
view:set-permissions This function sets the permissions for the named view in the named schema specification.
view:set-view-scope This function sets the scope of the named view in the named schema specification.
view:views This function returns all of the view specifications in the named schema.
Function Detail
view:add-column(
$schema-name as xs:string,
$view-name as xs:string,
$column as element(view:column)
)  as   empty-sequence()
Summary:

This function adds column specifications to the current set of column specifications on the named view in the named schema.

Parameters:
$schema-name : The name of the schema specification containing the view.
$view-name : The name of the view to which the column specifications are to be added.
$column : The column specifications to be added to the view.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";
 
  view:add-column("main", "songs",
      (view:column("author", cts:element-reference(xs:QName("AUTHOR")))) )

  (: Adds an 'author' column to the 'songs' view in the 'main' schema. :)
     

view:add-field(
$schema-name as xs:string,
$view-name as xs:string,
$field as element(view:field)
)  as   empty-sequence()
Summary:

This function adds a field to the named view.

Parameters:
$schema-name : The name of the schema.
$view-name : The name of the view.
$field : The field element to be added to the view.

Example:

xquery version "1.0-ml"; 
 
import module namespace view = "http://marklogic.com/xdmp/views" 
      at "/MarkLogic/views.xqy";
 
view:add-field("main", "employees", view:field("Employee"))

(: Adds the "Employee" field to the "employees" view. :)
    

view:add-permissions(
$schema-name as xs:string,
$view-name as xs:string,
$permissions as element(sec:permission)*
)  as   empty-sequence()
Summary:

This function adds permissions to those already set for the named view in the named schema specification.

Parameters:
$schema-name : The name of the schema specification containing the view.
$view-name : The name of the view to which the permissions are to be added.
$permissions : The permissions to be added to the view.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";
 
  view:add-permissions("main", "songs", (xdmp:permission("test-user", "read"),
                                         xdmp:permission("test-user", "update")))

  (: Enables users with the test-user role to read and update the 'main' schema. :)
     

view:collection(  ) as  xs:string
Summary:

This function return the URI of the protected collection holding all the views.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";

  view:collection()
 
  (: Returns the URI of the protected collection holding all of the views. :)
     

view:collection-view-scope(
$collection as xs:string
)  as   element(*, view:view-scope)
Summary:

This function constructs a new collection-style view scope specification.

For details on view scoping, see 'Defining View Scope' in the SQL Data Modeling Guide.


Parameters:
$collection : The name of the collection to define the view scope.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";
 
  view:collection-view-scope("http://marklogic.com/xdmp/view/songs")

  (: Returns a collection-style view scope specification. :)
     

view:column(
$name as xs:string,
$range-index as cts:reference
)  as   element(view:column)
Summary:

This function constructs a new column specification.

Parameters:
$name : The name of the column specification.
$range-index : The range index for the column.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";

  view:column("title", cts:element-reference(xs:QName("TITLE")))
 
  (: Constructs a column, named 'title', over an element range index, named 'TITLE'. :)
     

view:columns(
$schema-name as xs:string,
$view-name as xs:string
)  as   element(view:column)*
Summary:

This function returns the sequence of column specifications set in the named view in the named schema.

Parameters:
$schema-name : The name of the schema specification containing the view.
$view-name : The name of the view containing the column specifications.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";
 
  view:columns("main", "songs")

  (: Returns the columns set in the 'songs' view in the 'main' schema. :)
     

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 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.
$fields : A sequence of view fields. Each field has a name and a field 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:element-view-scope(
$localname as xs:QName
)  as   element(*, view:view-scope)
Summary:

This function constructs a new element-style view scope specification.

For details on view scoping, see 'Defining View Scope' in the SQL Data Modeling Guide.


Parameters:
$localname : The name of the element on which to define the view scope.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";
 
  view:element-view-scope(xs:QName("SONG"))

  (: Returns the view scope specification for the element, 'SONG'. :)
     

view:field(
$name as xs:string
)  as   element(view:field)
Summary:

This function constructs a new element-style field specification for the named field.

Parameters:
$name : The name of the field.

Example:

xquery version "1.0-ml"; 
 
import module namespace view = "http://marklogic.com/xdmp/views" 
      at "/MarkLogic/views.xqy";
 
view:field("Employee")

(: Constructs and element field specification for the "Employee" field. :)
    

view:fields(
$schema-name as xs:string,
$view-name as xs:string
)  as   element(view:field)*
Summary:

This function returns the fields set on the named view.

Parameters:
$schema-name : The name of the schema.
$view-name : The name of the view.

Example:

xquery version "1.0-ml"; 
 
import module namespace view = "http://marklogic.com/xdmp/views" 
      at "/MarkLogic/views.xqy";
 
view:fields("main", "employees") 

(: Returns the fields set on the "employees" view. :)
    

view:get(
$schema-name as xs:string,
$view-name as xs:string
)  as   element(view:view)
Summary:

This function returns the named view from the named schema specification.

Parameters:
$schema-name : The name of the schema containing the view.
$view-name : The name of the view.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";

  view:get("main", "songs")

  (: Returns the 'songs' view in the 'main' schema. :)
     

view:get-bindings(
$schema-name as xs:string,
$view-name as xs:string
)  as   map:map
Summary:

This function generates a binding map suitable for use with cts:parse from the named view.

Parameters:
$schema-name : The name of the schema.
$view-name : The name of the view.

Example:

xquery version "1.0-ml"; 
 
import module namespace view = "http://marklogic.com/xdmp/views" 
      at "/MarkLogic/views.xqy";
 
view:get-bindings("main", "employees")

(: Returns binging map from the "employees" view. :)
    

view:get-by-id(
$view-id as xs:unsignedLong
)  as   element(view:view)
Summary:

This function returns the view with the specified id.

Parameters:
$view-id : The id of the view to be returned.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";

  view:get-by-id(5423110979916486998)
 
  (: Return the view with the specified id. :)  
     

view:get-column(
$schema-name as xs:string,
$view-name as xs:string,
$column-name as xs:string
)  as   element(view:column)
Summary:

This function returns the named column specification set in the named view in the named schema.

Parameters:
$schema-name : The name of the schema specification containing the view.
$view-name : The name of the view containing the column specification.
$column-name : The name of the column specification to be returned.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";

  view:get-column("main", "songs", "title") 

  (: Returns the 'title' column from the 'songs' view in the 'main' schema. :)
     

view:get-field(
$schema-name as xs:string,
$view-name as xs:string,
$field-name as xs:string
)  as   element(view:field)
Summary:

This function returns the element specification for the named field.

Parameters:
$schema-name : The name of the schema.
$view-name : The name of the view.
$field-name : The name of the field.

Example:

xquery version "1.0-ml"; 
 
import module namespace view = "http://marklogic.com/xdmp/views" 
      at "/MarkLogic/views.xqy";

view:get-field("main", "employees",  "Employee") 

(: Returns the element specification for the "Employee" field. :)
    

view:get-permissions(
$schema-name as xs:string,
$view-name as xs:string
)  as   element(sec:permission)*
Summary:

This function returns the permissions set on the specified view.

Parameters:
$schema-name : The name of the schema that contains the view.
$view-name : The name of the view.

Example:

  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";
 
  view:get-permissions("main", "employees")

  (: Returns the permissions set on the 'employees' view in the 'main' schema. :)
    

view:get-view-scope(
$schema-name as xs:string,
$view-name as xs:string
)  as   element(*, view:view-scope)
Summary:

This function returns the scope of the named view in the named schema.

Parameters:
$schema-name : The name of the schema specification containing the view.
$view-name : The name of the view from which to return the scope.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";
 
  view:get-view-scope("main", "songs")
 
  (: Returns the scope of the 'songs' view in the 'main' schema. :)
     

view:remove(
$schema-name as xs:string,
$view-name as xs:string
)  as   empty-sequence()
Summary:

This function removes the named view from the named schema specification.

Parameters:
$schema-name : The name of the schema containing the view to be removed.
$view-name : The name of the view to be removed.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";
 
  view:remove("main", "songs")

  (: Removes the 'songs' view from the 'main' schema. :)
     

view:remove-by-id(
$view-id as xs:unsignedLong
)  as   empty-sequence()
Summary:

This function removes the view with the specified id.

Parameters:
$view-id : The id of the view to be removed.

Example:
 

  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";
 
  view:remove-by-id(5423110979916486998)

  (: Remove the view with the specified id. :)  
     

view:remove-column(
$schema-name as xs:string,
$view-name as xs:string,
$column-name as xs:string
)  as   empty-sequence()
Summary:

This function removes a column specification from the named view in the named schema.

Parameters:
$schema-name : The name of the schema specification containing the view.
$view-name : The name of the view from which the column specification is to be removed.
$column-name : The name of the column specification to be removed from the view.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";
 
  view:remove-column("main", "songs", "year")  

  (: Removes the 'year' column from the 'songs' view in the 'main' schema. :)
     

view:remove-field(
$schema-name as xs:string,
$view-name as xs:string,
$field-name as xs:string
)  as   empty-sequence()
Summary:

This function removes a field from the named view.

Parameters:
$schema-name : The name of the schema.
$view-name : The name of the view.
$field-name : The name of the field to be removed.

Example:

xquery version "1.0-ml"; 
 
import module namespace view = "http://marklogic.com/xdmp/views" 
      at "/MarkLogic/views.xqy";
 
view:remove-field("main", "employees", "Employee")

(: Removes the "Employee" field from the "employees" view. :)
    

view:remove-permissions(
$schema-name as xs:string,
$view-name as xs:string,
$permissions as element(sec:permission)*
)  as   empty-sequence()
Summary:

This function removes permissions from those set for the named view in the named schema specification.

Parameters:
$schema-name : The name of the schema specification containing the view.
$view-name : The name of the view from which the permissions are to be removed.
$permissions : The permissions to be removed from the view.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";
 
  view:remove-permissions("main", "songs", (xdmp:permission("test-user", "read"),
                                            xdmp:permission("test-user", "update")))

  (: Disables users with the test-user role from reading and updating the 
     'songs' view in the 'main' schema. :)
     

view:schema-add-permissions(
$schema-name as xs:string,
$permissions as element(sec:permission)*
)  as   empty-sequence()
Summary:

This function adds permissions to the specified schema specification.

Parameters:
$schema-name : The name of the schema specification.
$permissions : The permissions to add to the schema specification.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";

  view:schema-add-permissions("main", (xdmp:permission("test-user", "read"),
                                       xdmp:permission("test-user", "update")))

  (: Enables users with the test-user role to read and update the 'main' schema. :)
     

view:schema-create(
$schema-name as xs:string,
$permissions as element(sec:permission)*
)  as   xs:unsignedLong
Summary:

This function creates a new relational schema in the Schema database. The schema id is returned. Every SQL deployment must include a default schema, called "main," as shown in the example below.

Parameters:
$schema-name : The schema name. The schema name must be unique. A valid schema name is a single word that starts with an alpha character. The schema name may contain numeric characters, but cannot contain punctuation or special characters.
$permissions : Permissions that control access to the schema. If no permissions are specified, the default permissions are used.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";
 
  view:schema-create("main", ())

  (: Create a new schema, named 'main', using the default permissions. :)
     

view:schema-get(
$schema-name as xs:string
)  as   element(view:schema)
Summary:

This function returns the named schema specification document.

Parameters:
$schema-name : The name of the schema specification to return.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";

  view:schema-get("main")

  (: Return the schema, named 'main'. :)  
     

view:schema-get-permissions(
$schema-name as xs:string
)  as   element(sec:permission)*
Summary:

This function returns the permissions set on the specified schema.

Parameters:
$schema-name : The name of the schema.

Example:

  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";
 
  view:schema-get-permissions("main")

  (: Returns the permissions set on the 'main' schema. :)
    

view:schema-remove(
$schema-name as xs:string
)  as   empty-sequence()
Summary:

This function removes the specified schema. Removing a schema removes all the views that are part of that schema.

Parameters:
$schema-name : The name of the schema to be removed.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";
 
  view:schema-remove("main")

  (: Remove the schema, named 'main'. :) 
     

view:schema-remove-permissions(
$schema-name as xs:string,
$permissions as element(sec:permission)*
)  as   empty-sequence()
Summary:

This function removes permissions from the specified schema specification.

Parameters:
$schema-name : The name of the schema specification.
$permissions : The permissions to remove from the schema specification.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";

  view:schema-remove-permissions("main", (xdmp:permission("test-user", "read"),
                                          xdmp:permission("test-user", "update")))

  (: Disables users with the test-user role from reading and updating the 'main' schema. :) 
     

view:schema-set-permissions(
$schema-name as xs:string,
$permissions as element(sec:permission)*
)  as   empty-sequence()
Summary:

This function sets permissions on the specified schema specification. Any existing permissions for the schema and removed.

Parameters:
$schema-name : The name of the schema specification.
$permissions : The permissions to set on the schema specification.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";

  view:schema-set-permissions("main", (xdmp:permission("app-user", "read"),
                                       xdmp:permission("app-user", "update")))

  (: Enables only users with the app-user role to read and update the 'main' schema. :)
     

view:schemas(  ) as  element(view:schema)*
Summary:

This function returns all of the schema specifications.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";
 
  view:schemas()

  (: Returns all of the schema specifications. :)
     

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. :) 
     

view:set-fields(
$schema-name as xs:string,
$view-name as xs:string,
$fields as element(view:field)*
)  as   empty-sequence()
Summary:

This function sets the specified fields on the specified view. Any existing fields are replaced or removed.

Parameters:
$schema-name : The name of the schema.
$view-name : The name of the view.
$fields : The sequence of field elements to be set on the view.

Example:

xquery version "1.0-ml"; 
 
import module namespace view = "http://marklogic.com/xdmp/views" 
      at "/MarkLogic/views.xqy";
 
view:set-fields("main",
                "employees", 
                (view:field("Employee"), view:field("EmployeeID")) )

(: Sets the "Employee" and "EmployeeID" fields on the "employees" view. :)
    

view:set-name(
$schema-name as xs:string,
$view-name as xs:string,
$new-name as xs:string
)  as   empty-sequence()
Summary:

This function renames the named view in the named schema specification.

Parameters:
$schema-name : The name of the schema specification containing the view.
$view-name : The current name of the view to be renamed.
$new-name : The new name of the view. The view name must be unique in the context of the schema in which it resides. 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.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";
 
  view:set-name("main", "songs", "tunes")

  (: Renames the 'songs' view in the 'main' schema to 'tunes'. :)
     

view:set-permissions(
$schema-name as xs:string,
$view-name as xs:string,
$permissions as element(sec:permission)*
)  as   empty-sequence()
Summary:

This function sets the permissions for the named view in the named schema specification. Any existing permissions for the view and removed.

Parameters:
$schema-name : The name of the schema specification containing the view.
$view-name : The name of the view for which the permissions are to be set.
$permissions : The permissions for the view.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";

  view:set-permissions("main", "songs", (xdmp:permission("app-user", "read"),
                                         xdmp:permission("app-user", "update")))

  (: Enables only users with the app-user role to read and update the 'songs' view
     in the 'main' schema. :)
     

view:set-view-scope(
$schema-name as xs:string,
$view-name as xs:string,
$scope as element(*,view:view-scope)
)  as   empty-sequence()
Summary:

This function sets the scope of the named view in the named schema specification.

Parameters:
$schema-name : The name of the schema specification containing the view.
$view-name : The name of the view on which the scope is set.
$scope : The scope to be set on the view. 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.


Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";

  view:set-view-scope("main", "songs", view:element-view-scope(xs:QName("SONG"))) 

  (: Sets the scope of the 'songs' view in the 'main' schema to the 
     element, 'SONGS'. :)
     

view:views(
$schema-name as xs:string
)  as   element(view:view)*
Summary:

This function returns all of the view specifications in the named schema.

Parameters:
$schema-name : The name of the schema specification containing the views to be returned.

Example:
  xquery version "1.0-ml"; 
 
  import module namespace view = "http://marklogic.com/xdmp/view" 
      at "/MarkLogic/views.xqy";
 
  view:views("main")

  (: Returns all of the views in the 'main' schema. :)