-
Notifications
You must be signed in to change notification settings - Fork 6
Tilda JSON Syntax: Object And View Queries
<-- Object Syntax
<-- View Syntax
Queries allow you to specify more complex where clauses declaratively and have Tilda generate the appropriate glue code to retrieve one or more record from the database.
// Within an Object or view definition, you can define any number of queries (or none).
,"queries": [
{ "name" : "TemplateRefnum",
"description": "Get documents by template refnum",
"from" : [],
"wheres": [
{ "db": "*", "clause": "templateRefnum=?()" }
]
}
,{ "name" : "Category",
"description": "Get documents by template category",
"from" : [],
"wheres": [
{ "db": "*", "clause": "TILDA.in(category, ?()" } // Lookups up a single value
],
"orderBy": ["name asc" ]
}
,{ "name" : "Categories",
"description": "Get documents by template category",
"from" : [],
"wheres": [
{ "db": "*", "clause": "TILDA.in(category, ?[]" } // Lookups with multiple possible values
],
"orderBy": ["name asc" ]
}
,{ "name" : "TemplateId",
"description": "Search by bundle and cohort name",
"from" : ["com.myCo.documents.data.Docs.Template"],
"wheres": [
{ "db": "*", "clause": "Document.templateRefnum = Template.refnum and templateNname like '%?()%'" }
],
"orderBy": ["lastUpdated desc" ]
}
]
🎈 NOTE: There are limitations as to how complicated the where clause can be. The markers have to be near and after the actual variable. There are limitations to the current compiler code being used which we hope to improve in the future. For example, "x between ?(a) and ?(b)" works, but "biggest(a,b) > ?()" won't work as the compiler will think ?() binds to b. That may work if a and b are the exact same type on the java side though
🎈 NOTE: The marker syntax can be ?() or ?[]. In the case of ?[], a list type will be used in the generated Java code.
🎈 NOTE: The marker syntax can be augmented with an extra name, for example ?(start). This is common when doing range queries. So, for example "dt >= ?(Start) and dt < ?(End)" will generate a Java method with the signature (dtStart, dtEnd).
🎈 NOTE: By convention, if an "orderBy" is specified, it is assumed that multiple rows (possibly none) are returned. If no "orderBy" is specified, it is assumed that only one row (possibly none) is returned.
- The generated java code will return a list of results and the method will be called lookupWhereXXX() if an "orderBy" is specified.
- The generated java code will return a single result and the method will be called lookupByXXX() if no "orderBy" is specified.
- To generate a 'lookupWhere' semantic (multiple rows) without any logical orderBy (for a simple table scan for example), you need to supply an empty string, i.e. "orderBy":[""].
🎈 NOTE: Because the name-space of methods generated for indices and queries is the same, you must make sure that your query names and index names are unique.