As Reading API
CREATE TAG TABLE IF NOT EXISTS EXAMPLE (
NAME VARCHAR(20) PRIMARY KEY,
TIME DATETIME BASETIME,
VALUE DOUBLE SUMMARIZED);
INSERT INTO EXAMPLE VALUES('TAG0', TO_DATE('2021-08-12'), 10);
INSERT INTO EXAMPLE VALUES('TAG0', TO_DATE('2021-08-13'), 11);
When you save a TQL script, the editor will display a link icon in the top right corner. Click on it to copy the address of the script file.
CSV
Save the code below as output-csv.tql
.
|
|
Invoke the tql file with curl command.
$ curl http://127.0.0.1:5654/db/tql/output-csv.tql
TAG0,1628694000000000000,10
TAG0,1628780400000000000,11
Save the code below as output-csv.tql
.
|
|
Invoke the tql file with curl command.
$ curl http://127.0.0.1:5654/db/tql/output-csv.tql
TAG0|1628694000000000000|10
TAG0|1628780400000000000|11
JSON
Save the code below as output-json.tql
.
|
|
Invoke the tql file with curl command.
$ curl http://127.0.0.1:5654/db/tql/output-json.tql
{
"data": {
"columns": [ "NAME", "TIME", "VALUE" ],
"types": [ "string", "datetime", "double" ],
"rows": [
[ "TAG0", 1628694000000000000, 10 ],
[ "TAG0", 1628780400000000000, 11 ]
]
},
"success": true,
"reason": "success",
"elapse": "770.078µs"
}
Save the code below as output-json.tql
.
|
|
Invoke the tql file with curl command.
$ curl http://127.0.0.1:5654/db/tql/output-json.tql
{
"data": {
"columns": [ "NAME", "TIME", "VALUE" ],
"types": [ "string", "datetime", "double" ],
"cols": [
[ "TAG0", "TAG0" ],
[ 1628694000000000000, 1628780400000000000 ],
[ 10, 11 ]
]
},
"success": true,
"reason": "success",
"elapse": "718.625µs"
}
Save the code below as output-json.tql
.
|
|
Invoke the tql file with curl command.
$ curl http://127.0.0.1:5654/db/tql/output-json.tql
{
"data": {
"columns": [ "NAME", "TIME", "VALUE" ],
"types": [ "string", "datetime", "double" ],
"rows": [
"TAG0", 1628694000000000000, 10,
"TAG0", 1628780400000000000, 11
]
},
"success": true,
"reason": "success",
"elapse": "718.625µs"
}
Save the code below as output-json.tql
.
|
|
Invoke the tql file with curl command.
$ curl http://127.0.0.1:5654/db/tql/output-json.tql
{
"data": {
"columns": [ "NAME", "TIME", "VALUE" ],
"types": [ "string", "datetime", "double" ],
"rows": [
{ "NAME": "TAG0", "TIME": 1628694000000000000, "VALUE": 10 },
{ "NAME": "TAG0", "TIME": 1628780400000000000, "VALUE": 11 }
]
},
"success": true,
"reason": "success",
"elapse": "718.625µs"
}
MARKDOWN
Save the code below as output-markdown.tql
.
|
|
Invoke the tql file with curl command.
$ curl http://127.0.0.1:5654/db/tql/output-markdown.tql
|NAME|TIME|VALUE|
|:-----|:-----|:-----|
|TAG0|1628694000000000000|10.000000|
|TAG0|1628780400000000000|11.000000|
Save the code below as output-markdown.tql
.
|
|
Invoke the tql file with curl command.
$ curl http://127.0.0.1:5654/db/tql/output-markdown.tql
<div>
<table>
<thead>
<tr><th align="left">NAME</th><th align="left">TIME</th><th align="left">VALUE</th></tr>
</thead>
<tbody>
<tr><td align="left">TAG0</td><td align="left">1628694000000000000</td><td align="left">10.000000</td></tr>
<tr><td align="left">TAG0</td><td align="left">1628780400000000000</td><td align="left">11.000000</td>
</tr>
</tbody>
</table>
</div>
CHART
Save tql file
Save the code below as output-chart.tql
.
|
|
HTTP GET
Open web browser with http://127.0.0.1:5654/db/tql/output-chart.tql
The legacy
CHART_LINE()
,CHART_BAR()
,CHART_SCATTER()
and its family functions are deprecated with the newCHART()
function. Please refer to the CHART() for the examples.
CHART with chartJson()
Save tql file
Save the code below as output-chart.tql
.
|
|
HTTP GET
Open web browser with http://127.0.0.1:5654/db/tql/output-chart.tql
{
"chartID":"MzM3NjYzNjg5MTYxNjQ2MDg_",
"jsAssets": ["/web/echarts/echarts.min.js"],
"jsCodeAssets": ["/web/api/tql-assets/MzM3NjYzNjg5MTYxNjQ2MDg_.js"],
"style": {
"width": "600px",
"height": "600px"
},
"theme": "white"
}
CHART with chartID()
Save tql file
Save the code below as output-chart.tql
.
|
|
HTTP GET
Open web browser with http://127.0.0.1:5654/db/tql/output-chart.tql
{
"chartID":"myChart",
"jsAssets": ["/web/echarts/echarts.min.js"],
"jsCodeAssets": ["/web/api/tql-assets/myChart.js"],
"style": {
"width": "600px",
"height": "600px"
},
"theme": "white"
}
This scenario is useful when your DOM document has <div id='myChart'/>
.
... in HTML ...
<div id='myChart' />
<script>
fetch('http://127.0.0.1:5654/db/tql/output-chart.tql').then( function(rsp) {
return rsp.json();
}).then( function(c) {
c.jsAssets.concat(c.jsCodeAssets).forEach((src) => {
const sScript = document.createElement('script');
sScript.src = src;
sScript.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(sScript);
})
})
</script>
... omit ...