es:model-get-test-instances( $model as map:map ) as element()*
This function is deprecated and will be removed in a future release.
Generate entity instances of each entity type in a basic model.
Parameters | |
---|---|
model | A valid basic model. |
This function is useful for examining what entity instances will look like by default and for testing code that manipulates entities.
A single test entity instance is generated for each entity type defined by the input basic model. Each instance is an XML element that is a valid representation of the entity type, although it might not be exactly what an implementation your application requires.
For each property in an entity type, this function emits an element
containing a dummy value of the property's type. If a property is a
reference to an entity type that can be resolved local to this model,
then an instance of the referenced type is embedded within the referring
instance. If a property is an array, only one element of the array item
type is generated, but it has a datatype
attribute that
indicates it is an array. See the example below.
xquery version "1.0-ml"; import module namespace es = "http://marklogic.com/entity-services" at "/MarkLogic/entity-services/entity-services.xqy"; es:model-get-test-instances( es:model-validate( <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> <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> <Person> <es:properties> <id><es:datatype>int</es:datatype></id> <name><es:ref>#/definitions/Name</es:ref></name> <bio><es:datatype>string</es:datatype></bio> <rating><es:datatype>float</es:datatype></rating> <phone> <es:datatype>array</es:datatype> <es:items><es:datatype>string</es:datatype></es:items> </phone> </es:properties> <es:primary-key>id</es:primary-key> <es:required>id</es:required> <es:required>name</es:required> </Person> </es:definitions> </es:model> )) (: ==> Two test instances, one for Name and one for Person. MarkLogic produces output similar to the following. <Name> <first>some string</first> <middle>some string</middle> <last>some string</last> </Name> <Person> <id>123</id> <name> <Name> <first>some string</first> <middle>some string</middle> <last>some string</last> </Name> </name> <bio>some string</bio> <rating>123</rating> <phone datatype="array">some string</phone> </Person> :)