Sample - nativelogix/slush-xquerrail GitHub Wiki

New XQuerrail project using slush generator

Install Slush XQuerrail

Prerequisite

NodeJS must be installed

npm install -g nativelogix/slush-xquerrail

Create a new directory

mkdir hello-xquerrail

Create skeleton project

slush xquerrail
Answer the following questions
? What is the name of your project? hello-xquerrail
? What is the description or your project? Hello XQuerrail
? What is the version of your project? 0.1.0
? XQuerrail version? 0.0.12
? What is XQuerrail application name? app
? What is the application namespace? Supported format {prefix}:{namespace} application:http://xquerrail.com/application)
? What is the content namespace? Supported format {prefix}:{namespace} content:http://xquerrail.com/content)
? What is the application collation? http://marklogic.com/collation/codepoint
? What is the author name? Richard Louapre
? What is the author email? [email protected]
? Continue? Yes

TODO: Describe the folder structure generated

Setup Roxy

Prerequisite

Ruby must be installed

slush xquerrail:roxy
Answer the following questions
? Roxy version? 1.7.2
? MarkLogic version? 8
? Marklogic host? 192.168.1.99
? Application name? hello-xquerrail
? Application port? 9200
? Bootstrap user? admin
? Bootstrap password? ******
? Continue? Yes

A new roxy directory has been created. Roxy has been pre-configured according to the settings provided.

Create new application

cd roxy && ./ml local bootstrap && cd ..

Load modules

cd roxy && ./ml local deploy modules && cd ..

Take a look at Roxy documentation https://github.com/marklogic/roxy to get more details about the commands available.

Validation

This url will initialize XQuerrail http://${host}:${port}/initialize
Or use the custom Roxy command:
cd roxy && ./ml local initialize_xquerrail && cd ..

Inspect the application definition http://${host}:${port}/applications/get.xml

Inspect the application domain (empty for now) http://${host}:${port}/applications/app/domain/get.xml

Create a model

Create an author model with 4 string fields: firstName,lastName,email and publicationCount. email will be the key.

slush xquerrail:model
? What is the model name? author
? What is the model persistence? directory
? What is the base class?
? What is the model collation?
? List the field names (comma separated)? firstName,lastName,email,publicationCount
? What is the key field? email
? What is the key label field? email
? Create Xray tests? Yes
? Create controller? Yes
? Controller name? authors
? Create Mocha tests? Yes
? Continue? Yes

Deploy updated domain model: cd roxy && ./ml local deploy modules && cd ..

Reload XQuerrail application: http://${host}:${port}/initialize
Or use the custom Roxy command:
cd roxy && ./ml local initialize_xquerrail && cd ..

Generate indexes require by the application domain:
cd roxy && ./ml local build_indexes && cd ..

Validate new controller (from list action)

http://${host}:${port}/authors/list.xml

Run XRay tests (unit test for model)

XRay unit test has been generated in src/test/xray/author-test.xqy It can be executed from this url: http://${host}:${port}/xray

Run Mocha tests (unit test for controller)

Mocha test has been generated in src/test/mocha/test/author-test.js It can be executed from the command line: gulp mocha

Run all tests

Pre-configure build script is available (perfect for CI) Just run gulp test

Create complex model

List of supported data types
Create a manuscript model with 6 fields:

  • id (unique identifier auto-generated)
  • title
  • pages (integer - number of pages)
  • created (date - creation date)
  • modified (dateTime - modified date)
  • author (reference to author)
    id will be the key.

slush xquerrail:model
? What is the model name? manuscript
? What is the model persistence? directory
? What is the base class?
? What is the model collation?
? List the field names (comma separated)? id[id],title[s],pages[i],created[dt],modified[dtm],author[ref]
? What is the key field? id[id]
? What is the key label field? title[s]
? Create Xray tests? Yes
? Create controller? Yes
? Controller name? manuscripts
? Create Mocha tests? Yes
? Continue? Yes

Reload application and create indexes

cd roxy && ./ml local deploy modules && cd ..
cd roxy && ./ml local initialize_xquerrail && cd ..
cd roxy && ./ml local build_indexes && cd ..

Test from the APIS

Create a new entity
curl --anyauth --user public/admin:secret -XPOST 192.168.1.99:9200/authors/create.xml -H 'Content-Type: application/xml' --data '<author xmlns="http://xquerrail.com/application"><firstName>richard</firstName><lastName>louapre</lastName><email>[email protected]</email></author>'
Get entity
curl --anyauth --user public/admin:secret -XGET 192.168.1.99:9200/authors/[email protected] -H 'Accept: application/xml'

⚠️ **GitHub.com Fallback** ⚠️