OpenWGA 7.0 - TMLScript reference
DatabaseMethod :
query(queryType, query, [attributes, [queryParams, [context]]])
On object | Database |
Usage | Performs a query on the database |
Description |
This method is the TMLScript pendant to WebTML tag <tml:query> and works quite equal. The mandatory parameters "queryType" and "query" are equal to attribute type and the contents of the query tag. The Lookup table argument "attributes" uses the names of other <tml:query>-Attributes as keys and interprets them the same way. So filling it with an entry of key "max" and a value 100 will have the same effect as specifying attribute max="100" on a query tag. Specifying or omitting an attribute here has the same effect as it would have on <tml:query>. The Lookup table argument "queryParams" takes query parameters that in WebTML you would be added to the query by using <tml:param>. Specify parameter names as keys and parameter values as values. The argument "context" determines the WebTML context for which the query runs, which is important for some query types like "lucene" or "hdbmodel:*". |
Parameters |
queryType (String): The type of query to execute. See Query languages reference for valid values query (String): The actual query to execute attributes (Lookup table, optional): Additional attributes for the query. Specify names of <tml:query> attributes and use the desired attribute values. Values might either be in string or in native type. So value of attribute "max" could be specified as string "100" or as native JavaScript number 100. queryParams (Lookup table, optional): Query parameters injected to the query. Specify parameter names as keys. Values may be any value that would be valid as a result of <tml:param>-attribute expression. context (TMLContext, optional): The context to execute the query for. Omit this to execute the query under the context of the script. |
Return value | A QueryResult object |
Allowed in script types |
|
Examples |
Executing a simple HQL query: WGA.app().query("hql", "content.author = 'ow'"); This returns the same results as: <tml:query type="hql">content.author = 'ow'</tml:query> Controlling query behaviour using some additional attributes. Note that we use the JSON object syntax on the "attributes" argument instead of a native Lookup table for simplicity (JavaScript objects can be used wherever Lookup Tables are expected). WGA.app().query( "hql", "content.author = 'ow'", {max: 100, cache:true} ); Extending this even further by injecting the author name to query as query parameter: WGA.app().query( "hql", "content.author = :author", {max: 100, cache:true}, {author: "ow"} ); An example of traversing query results, which puts all resulting contents in a list: var list = WGA.createList(); var result = WGA.app().query("hql", "content.author = 'ow'"); for (con in Iterator(result.set)) { list.add(con); } |