PageSourceSearch

https://docs.brightspot.com/assets/js/4e3de29b.bc7cffb6.js

js brightspot.com collected 2026-10-02 05:53:50 UTC 9,885 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunktemp=self.webpackChunktemp||[]).push([["10761"],{930874:function(e,r,s){s.r(r),s.d(r,{assets:()=>c,contentTitle:()=>o,default:()=>h,frontMatter:()=>d,metadata:()=>t,toc:()=>a});var t=s(895477),i=s(785893),n=s(250065);let d={brightspotPermalink:"/brightspot-cms-developer-guide/latest/querying",brightspotId:"0000017d-763b-d029-adff-77bb60cd0000",slug:"/querying"},o="Querying",c={},a=[{value:"Overview of querying with Dari",id:"overview-of-querying-with-dari",level:2}];function l(e){let r={a:"a",code:"code",h1:"h1",h2:"h2",header:"header",p:"p",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,n.a)(),...e.components},{Code:s}=r;return s||function(e,r){throw Error("Expected "+(r?"component":"object")+" `"+e+"` to be defined: you likely forgot to import, pass, or provide it.")}("Code",!0),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(r.header,{children:(0,i.jsx)(r.h1,{id:"querying",children:"Querying"})}),"\n",(0,i.jsxs)(r.p,{children:["The Query API is an abstraction layer that provides a single query syntax regardless of the underlying database type. Queries are represented by instances of the ",(0,i.jsx)(r.a,{href:"https://artifactory.psdops.com/psddev-releases/com/psddev/dari-db/3.3.607-xe0f27a/dari-db-3.3.607-xe0f27a-javadoc.jar!/com/psddev/dari/db/Query.html",children:"Query"})," class. This class will look familiar if you have used SQL before."]}),"\n",(0,i.jsxs)(r.p,{children:["You can use the ",(0,i.jsx)(r.a,{href:"/docs/developer/debugging-with-dari",children:"Code Editor"})," to test queries. For additional debugging functionality, see the ",(0,i.jsx)(r.a,{href:"/docs/developer/database-query",children:"Database Query Tool"}),"."]}),"\n",(0,i.jsx)(r.h2,{id:"overview-of-querying-with-dari",children:"Overview of querying with Dari"}),"\n",(0,i.jsxs)(r.p,{children:["The ",(0,i.jsx)(r.a,{href:"https://artifactory.psdops.com/psddev-releases/com/psddev/dari-db/3.3.607-xe0f27a/dari-db-3.3.607-xe0f27a-javadoc.jar!/com/psddev/dari/db/Query.html",children:"Query"})," API provides several methods for specifying the types of objects to be retrieved, for filtering results, and for executing actions on retrieved objects. A typical Dari query is expressed as a chain of methods, as shown in this diagram of a basic query. The API methods correspond to SQL clauses, described in the table that follows."]}),"\n",(0,i.jsx)(s,{codeblock:{value:"Query.from(<class>)\n    .where(<predicate>)\n    .and | .or | .not (<predicate>)\n    .sortAscending | .sortDescending\n    .selectAll | .first()\n    /* OR */\n    .select(<range>)\n    /* OR */\n    .groupBy<fields>",lang:"java",meta:"",code:"Query.from(<class>)\n    .where(<predicate>)\n    .and | .or | .not (<predicate>)\n    .sortAscending | .sortDescending\n    .selectAll | .first()\n    /* OR */\n    .select(<range>)\n    /* OR */\n    .groupBy<fields>",tokens:[["Query.","#24292F"],["from","#8250DF"],["(","#24292F"],["<","#CF222E"],["class","#24292F"],[">","#CF222E"],[")","#24292F"],"\n    ",[".","#24292F"],["where","#8250DF"],["(","#24292F"],["<","#CF222E"],["predicate","#24292F"],[">","#CF222E"],[")","#24292F"],"\n    ",[".and","#24292F"]," ",["|","#CF222E"]," ",[".or","#24292F"]," ",["|","#CF222E"]," ",[".","#24292F"],["not","#8250DF"]," ",["(","#24292F"],["<","#CF222E"],["predicate","#24292F"],[">","#CF222E"],[")","#24292F"],"\n    ",[".sortAscending","#24292F"]," ",["|","#CF222E"]," ",[".sortDescending","#24292F"],"\n    ",[".selectAll","#24292F"]," ",["|","#CF222E"]," ",[".","#24292F"],["first","#8250DF"],["()","#24292F"],"\n    ",["/* OR */","#6E7781"],"\n    ",[".","#24292F"],["select","#8250DF"],["(","#24292F"],["<","#CF222E"],["range","#24292F"],[">","#CF222E"],[")","#24292F"],"\n    ",["/* OR */","#6E7781"],"\n    ",[".groupBy","#24292F"],["<","#CF222E"],["fields","#24292F"],[">","#CF222E"]],annotations:[],themeName:"github-light",style:{color:"#24292f",background:"#ffffff"}}}),"\n",(0,i.jsxs)(r.table,{children:[(0,i.jsx)(r.thead,{children:(0,i.jsxs)(r.tr,{children:[(0,i.jsx)(r.th,{children:"Query Clause"}),(0,i.jsx)(r.th,{children:"Description"})]})}),(0,i.jsxs)(r.tbody,{children:[(0,i.jsxs)(r.tr,{children:[(0,i.jsx)(r.td,{children:(0,i.jsx)(r.code,{children:"from<class>"})}),(0,i.jsxs)(r.td,{children:["Specifies the class type on which to search for instances. The following query creates a ",(0,i.jsx)(r.code,{children:"Query"})," object that retrieves all ",(0,i.jsx)(r.code,{children:"Article"})," objects: ",(0,i.jsx)(r.code,{children:"Query query = Query.from(Article.class);"})," There are several from-related methods that specify the object type to search for. See FROM."]})]}),(0,i.jsxs)(r.tr,{children:[(0,i.jsx)(r.td,{children:(0,i.jsx)(r.code,{children:"where<predicate>"})}),(0,i.jsxs)(r.td,{children:["Specifies predicates to filter search results. You can express conditions with comparison, compound, and other operators. The following query retrieves an ",(0,i.jsx)(r.code,{children:"Article"})," object with the specified headline: ",(0,i.jsx)(r.code,{children:'Query query = Query.from(Article.class).where(headline = "Marshmallow Dreams");'})," Alternatively, you can express conditions using predicate objects instead of string operators. To express predicates with object operands, you can use bind variables and object references to simplify your query constructs."]})]}),(0,i.jsxs)(r.tr,{children:[(0,i.jsx)(r.td,{children:(0,i.jsx)(r.code,{children:"and | or | not<predicate>"})}),(0,i.jsxs)(r.td,{children:["Represents logical operations ",(0,i.jsx)(r.code,{children:"AND"}),", ",(0,i.jsx)(r.code,{children:"OR"}),", ",(0,i.jsx)(r.code,{children:"NOT"})," to combine additional predicates with the predicate expressed in the ",(0,i.jsx)(r.code,{children:"where"})," clause. The following query retrieves an ",(0,i.jsx)(r.code,{children:"Article"})," object with one of two specified headlines: ",(0,i.jsx)(r.code,{children:'Query query = Query.from(Article.class).where(headline = "Marshmallow Dreams").or(headline = "Cotton Candy Fantasies");'})]})]}),(0,i.jsxs)(r.tr,{children:[(0,i.jsx)(r.td,{children:(0,i.jsx)(r.code,{children:"sortAscending | sortDescending<field>"})}),(0,i.jsxs)(r.td,{children:["Sorts results by field, in ascending or descending order. The following query sorts ",(0,i.jsx)(r.code,{children:"Author"})," objects in ascending alphabetical order by last name: ",(0,i.jsx)(r.code,{children:'List authors = Query.from(Author.class).sortAscending("lastName");'})," There are several sort-related methods. See Sorting."]})]}),(0,i.jsxs)(r.tr,{children:[(0,i.jsx)(r.td,{children:(0,i.jsx)(r.code,{children:"selectAll() | first()"})}),(0,i.jsxs)(r.td,{children:["Specifies the objects to be selected from the query results. See FROM. ",(0,i.jsx)(r.code,{children:"selectAll()"})," selects all instances retrieved by the query: ",(0,i.jsx)(r.code,{children:"List articles = Query.from(Article.class).selectAll();"})," ",(0,i.jsx)(r.code,{children:"first()"})," selects only the first instance retrieved by the query: ",(0,i.jsx)(r.code,{children:"Article article = Query.from(Article.class).first();"})]})]}),(0,i.jsxs)(r.tr,{children:[(0,i.jsx)(r.td,{children:(0,i.jsx)(r.code,{children:"select<range>"})}),(0,i.jsxs)(r.td,{children:["Specifies the number of instances to return in a paginated result. The following query limits the number of articles returned at any one time to 100, referenced in a ",(0,i.jsx)(r.code,{children:"PaginatedResult"})," object: ",(0,i.jsx)(r.code,{children:"PaginatedResult results = Query.from(Article.class).select(0, 99);"})," Subsequent calls can be made on ",(0,i.jsx)(r.code,{children:"PaginatedResult"})," to return additional batches of articles."]})]}),(0,i.jsxs)(r.tr,{children:[(0,i.jsx)(r.td,{children:(0,i.jsx)(r.code,{children:"groupBy<fields>"})}),(0,i.jsxs)(r.td,{children:["Groups retrieved objects by field, with objects with the same field value placed into the same grouping. The following query groups the articles returned by ",(0,i.jsx)(r.code,{children:"author"})," field, with articles by the same author grouped together: ",(0,i.jsx)(r.code,{children:'List<Grouping> groupings = Query.from(Article.class).groupBy("author");'})]})]})]})]}),"\n",(0,i.jsxs)(r.p,{children:["The Query API includes methods to retrieve objects as reference-only. For more information, see ",(0,i.jsx)(r.a,{href:"/docs/developer/advanced",children:"Advanced"}),"."]})]})}function h(e={}){let{wrapper:r}={...(0,n.a)(),...e.components};return r?(0,i.jsx)(r,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},250065:function(e,r,s){s.d(r,{Z:()=>o,a:()=>d});var t=s(667294);let i={},n=t.createContext(i);function d(e){let r=t.useContext(n);return t.useMemo(function(){return"function"==typeof e?e(r):{...r,...e}},[r,e])}function o(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:d(e.components),t.createElement(n.Provider,{value:r},e.children)}},895477:function(e){e.exports=JSON.parse('{"id":"dari-guide/querying/querying","title":"Querying","description":"The Query API is an abstraction layer that provides a single query syntax regardless of the underlying database type. Queries are represented by instances of the Query class. This class will look familiar if you have used SQL before.","source":"@site/bundle/public/docs/developer/default/dari-guide/querying/querying.md","sourceDirName":"dari-guide/querying","slug":"/querying","permalink":"/docs/developer/querying","draft":false,"unlisted":false,"tags":[],"version":"current","frontMatter":{"brightspotPermalink":"/brightspot-cms-developer-guide/latest/querying","brightspotId":"0000017d-763b-d029-adff-77bb60cd0000","slug":"/querying"},"sidebar":"developer","previous":{"title":"Configuring StorageItem","permalink":"/docs/developer/configuring-storageitem"},"next":{"title":"FROM","permalink":"/docs/developer/from"}}')}
1}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.