Server Services
Server Services
Status: client request/response, the services engine and the QML API are implemented. Migration of the legacy history screens is in progress.
Clients never send SQL. They call a named service with typed parameters; the service is declared in your server QML, so adding one needs no recompilation of the server or the client.
Client (KzRequest / KzTable) --REQUEST--> kazad --> validation, ACL, limits └ KzService (QML) --> read-only SQL pool <--RESPONSE-- table or value, status, never any SQL
Declarative service
KzService { name: "ecowitt.history" description: "Weather metric, min/avg/max per step" sql: "SELECT time_bucket(:step::interval, time) AS t, min(%metric%), avg(%metric%), max(%metric%) FROM ecowitt WHERE time >= :start AND time < :end GROUP BY t ORDER BY t" params: [ KzParam { name: "start"; type: KzParam.DateTime; required: true }, KzParam { name: "end"; type: KzParam.DateTime; required: true }, KzParam { name: "step"; type: KzParam.Enum values: ["10 minutes", "1 hour", "1 day"]; defaultValue: "1 hour" }, KzParam { name: "metric"; type: KzParam.Identifier values: ["temp", "humidity", "baromrel"] } ] maxRows: 5000 timeout: 10000 users: ["*"] }
-
:nameis a bound value, never concatenated. -
%name%substitutes an identifier, only forIdentifierparameters restricted to a closed list. - Parameter types:
Int,Double,Bool,String,DateTime,Enum,Identifier, withrequired,defaultValue,min,max,values,maxLength. - A placeholder without matching parameter is rejected when the QML loads, not at run time.
Scriptable service
KzService { name: "energy.summary" params: [ KzParam { name: "since"; type: KzParam.DateTime; required: true } ] handler: function(req) { kazamanager.query("SELECT sum(kwh) FROM energy WHERE day >= :d", { d: req.params.since }, function(r) { if (!r.ok) { req.fail("db"); return } req.respondValue(r.rows[0][0]) }) } }
The handler runs on the main thread and must not block. Queries run asynchronously in a read-only transaction. Replies: respondTable, respondValue, respondEmpty, fail, invalid. Without a reply before timeout, the client receives TIMEOUT.
Guarantees
- Read-only, bounded rows and time, per-client in-flight limit.
- A service the user may not call looks the same as one that does not exist.
- Errors sent to clients never contain SQL, table names or paths; details go to the server log.
- Built-in
kaza.historyreproduces the old history behaviour (domainstemperature,tanklevel).
Client side
In client QML, KzRequest and KzTable call a service and expose the rows. See the Integrator Guide.
Status codes
OK, UNKNOWN_SERVICE, INVALID_PARAMS, TIMEOUT, BUSY, TOO_LARGE, UNAVAILABLE, INTERNAL.