Inlining Data

To avoid content flash on initial application loading, you can embed an SQL query in your application html. When sends the app html page to the browser, it scans for an embedded query, executes the query, and inlines the results, as JSON, into the html.

How To:

The embedded SQL is part of a script tag, as attribute 'sql' or 'data-sql'. The query is executed as the role given by the 'role' or 'data-role' attribute, by default the preauth role.. The script must have id 'RDBHOST-SQL-INLINE-ID', and be of a type that the browser will ignore. I suggest type 'text/sql'.

Usage Example

<script id="RDBHOST-SQL-INLINE-ID" type="text/sql" data-sql="SELECT * FROM samples"

var json = $('#RDBHOST-SQL-INLINE-ID').html(),
data = JSON.parse(json),
// do something with data

This example will have records from the table samples included, as JSON in the usual RdbHost format, as the body of the script tag, when the page initially loads in the browser. The JavaScript segment reads that body, converts it to JavaScript data, and does something with it, presumably passing it to a templater.

If the query errors, the error will be provided as the body, in the usual RdbHost JSON error format.