[Q&A Friday] SELECT clause in Nuxeo NXQL queries
while this is working fine:
[email protected]:/> query "select * from myDocumentType"
Frank is actually running those queries from Nuxeo Shell. The query command uses the Document.Query operation which itself uses CoreSession#query. This method will only return a DocumentModelList so you cannot use a specific select clause in your query. And this makes sense, because with Content Automation, you usually manipulate Documents.
So when can you use a specific select clause? You have to use CoreSession#queryAndFetch. This will return an IterableQueryResult. If you still want to do your query from the shell, a quick and easy way to do it is to use a Groovy script like this:
iterableQueryResult = Session.queryAndFetch("SELECT dc:title,ecm:uuid FROM Document WHERE dc:title = 'Workspace'", "NXQL");
out = "";
out += iterableQueryResult.next().toString() + "n";
// don't forget to close it!
To call it you have to use the script command and give it the path of your Groovy script:
[email protected]:/> script /home/ldoguin/test.groovy
If you want to know more about Nuxeo's NXQL, take a look at the documentation.
Category: Product & Development