This is a collection of mini-recipes for doing JCR queries. Please add your own!
|
SQL |
XPath (deprecated in JCR 2.0) |
SQL2 |
---|---|---|---|
Get all pages |
select * from mgnl:content |
//element(*, mgnl:content) |
select * from [mgnl:page] |
Get all pages with "News" in the title |
select * from mgnl:content where title like '%News%' |
//element(*, mgnl:content)[jcr:like(@title, '%News%')] |
select * from [mgnl:page] where title like '%News%' |
Get all pages where the title exactly matches "News" (case sensitive) |
select * from mgnl:content where title like 'News' |
//element(*, mgnl:content)[@title = 'News'] |
select * from [mgnl:page] where title like 'News' |
Get all STK pages that have a header image |
select * from mgnl:content where image is not null |
//element(*, mgnl:content)[@image] |
select * from [mgnl:page] where image is not null |
Get all instances of a "Teaser" paragraph |
select * from nt:base where mgnl:template = 'stkTeaser' |
//*[@mgnl:template = 'stkTeaser'] |
select * from [nt:base] where [mgnl:template] = 'standard-templating-kit:components/teasers/stkTeaser' |
Get listing of available paragraph types |
select * from nt:base where jcr:path like '/modules/%/paragraphs/%' and type is not null |
/jcr:root/modules[1]///paragraphs[1]//[@type] |
|
Get user with email 'eric@example.com' |
select * from mgnl:user where email = 'eric@example.com' |
//element(*, mgnl:user)[@email = 'eric@example.com'] |
select * from [mgnl:user] where email = 'eric@example.com' |
Get all pages where word "component" is |
SELECT * from nt:base WHERE jcr:path like '/ftl-sample-site%' AND contains(*, 'component') AND (jcr:primaryType = 'mgnl:page' OR jcr:primaryType = 'mgnl:area' OR jcr:primaryType = 'mgnl:component') order by jcr:path |
|
SELECT * from [nt:base] AS t WHERE ISDESCENDANTNODE([/ftl-sample-site]) AND contains(t.*, 'component') |
Get all templates folders from modules config |
select * from mgnl:content where jcr:path like '/modules/%/templates' |
|
select * from [mgnl:content] as t where ISDESCENDANTNODE([/modules]) and name(t) = 'templates' |
Commands provided by modules |
select * from nt:base where jcr:path like '/modules/%/commands/%' |
|
select * from [mgnl:content] as t where ISDESCENDANTNODE([/modules]) and name(t) = 'commands' |
Note: you can use the translator to convert from one format to another.