Loading TOC...

MarkLogic Server 11.0 Product Documentation
es:version-translator-generate

es:version-translator-generate(
   $source-model as map:map,
   $target-model as map:map
) as xs:string

Summary

This function is deprecated and will be removed in a future release.
Generate a module that can be used to translate instances conforming to one version of a model into instances conforming to another version

Parameters
source-model The basic model for the "older" version of the model. This is the model to translate data from.
target-model The basic model for the "newer" version of the model. This is the model to translate data to.

Usage Notes

This function compares two versions of a basic model and generates an XQuery library module you can use to transform instance data from one version to the other. Use this function as part of managing a data model lifecycle. As the model for an entity type changes over time, you can use the output of this function as the basis for code that helps with migrating dependent services and transforms from source data systems.

The generated XQuery module contains one function per entity type in target-model. Each such function stubs out the conversion of one entity type to another. You can use these functions in concert with transform code to implement runtime versioning transforms.

You will typically need to install the generated module in your modules database before you can use it.

See Also

Example

(: Generate a translator module between two versions of a basic model.
 : The models only differ in that the new version contains an additional
 : (optional) property named "middle" in the Name entity type. 
 :)
xquery version "1.0-ml";
import module namespace es = "http://marklogic.com/entity-services"
  at "/MarkLogic/entity-services/entity-services.xqy";

let $v1-model := es:model-from-xml(
  <es:model xmlns:es="http://marklogic.com/entity-services">
    <es:info>
      <es:title>Example</es:title>
      <es:version>1.0.0</es:version>
      <es:description>ES Examples</es:description>
    </es:info>
    <es:definitions>
      <Name>
        <es:properties>
          <first><es:datatype>string</es:datatype></first>
          <last><es:datatype>string</es:datatype></last>
        </es:properties>
        <es:required>first</es:required>
        <es:required>last</es:required>
      </Name>
    </es:definitions>
  </es:model>
)
let $v2-model := es:model-from-xml(
  <es:model xmlns:es="http://marklogic.com/entity-services">
    <es:info>
      <es:title>Example</es:title>
      <es:version>2.0.0</es:version>
      <es:description>ES Examples</es:description>
    </es:info>
    <es:definitions>
      <Name>
        <es:properties>
          <first><es:datatype>string</es:datatype></first>
          <middle><es:datatype>string</es:datatype></middle>
          <last><es:datatype>string</es:datatype></last>
        </es:properties>
        <es:required>first</es:required>
        <es:required>last</es:required>
      </Name>
    </es:definitions>
  </es:model>
)
return es:version-translator-generate($v1-model, $v2-model)

==> An XQuery library module similar to the following. Some of the
    comments in the generated module have been omitted for brevity.

xquery version "1.0-ml";
module namespace example-from-example
    = "http://example.org/Example-2.0.0-from-Example-1.0.0";

import module namespace es = "http://marklogic.com/entity-services"
    at "/MarkLogic/entity-services/entity-services.xqy";

declare option xdmp:mapping "false";

declare function example-from-example:convert-instance-Name(
    $source-node as node()
) as map:map
{
    json:object()
    (: The following line identifies the type of this instance.  Do not change it. :)
    =>map:with('$type', 'Name')
    (: The following lines are generated from the 'Name' entity type. :)
    =>   map:with('first',                  xs:string($source-node/Name/first))
    (: The following property was missing from the source type :)
    =>es:optional('middle',                 xs:string( () ))
    =>   map:with('last',                   xs:string($source-node/Name/last))

};
  

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