Skip to content

Instantly share code, notes, and snippets.

@ableasdale
Created May 14, 2014 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ableasdale/aa3da34ba8f5e5d96f08 to your computer and use it in GitHub Desktop.
Save ableasdale/aa3da34ba8f5e5d96f08 to your computer and use it in GitHub Desktop.
Create sample data in a given database quickly
xquery version "1.0-ml";
declare private function local:random-hex($length as xs:integer) as xs:string {
fn:string-join(for $n in 1 to $length
return xdmp:integer-to-hex(xdmp:random(15)),
""
)
};
declare function local:generate-uuid-v4() as xs:string {
fn:string-join(
(
local:random-hex(8),
local:random-hex(4),
local:random-hex(4),
local:random-hex(4),
local:random-hex(12)
),
"-"
)
};
(: main :)
for $i in (1 to 50000)
let $guid := local:generate-uuid-v4()
return
xdmp:document-insert(concat($guid,".xml"),
<data>
<dateTime>{fn:current-dateTime()}</dateTime>
<guid>{$guid}</guid>
</data>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment