I have a StreamBase
app that queries data and put it into a .lvconf table.
Is there a way to get the data from this .lvconf
table and have it available in my JavaScript
for me to do things with the data?
1 Answers
Assuming that .lvconf
table means a data table in a LiveView server (also known as Live Datamart), the way to access data from the table in a JavaScript application is to use the LiveView JavaScript Client API. (There is API reference documentation as well.)
Here is a short example of using the API to query a Live Datamart table called ItemsInventory:
<script src="/lv-web/api/lib/jquery.min.js"></script>
<script src="/lv-web/api/lib/jquery.atmosphere.min.js"></script>
<script src="/lv-web/api/liveview.min.js"></script>
<script>
LiveView.connect({url: '/lv/client/'}).then(
function(connection){
connection.subscribe(
new LiveView.Query('SELECT * FROM ItemsInventory'),
{
onInsert: function(result){
console.log('Got new tuple: ' + JSON.stringify(result.tuple));
}
}
);
}
);
</script>
The Creating web applications with JavaScript sample shipped with LiveView further illustrates the use of the JavaScript Client API for table querying.
To load this sample in StreamBase Studio:
- Select File → Load StreamBase Sample from Studio's top-level menu.
- Enter "javasc" in the filter field to narrow the selection.
- Select the sample whose description is Creating web applications with JavaScript from the TIBCO LiveView category.
- Click OK.
Follow the instructions in the sample's README.txt file to run the sample project as a LiveView Project.
Since this question and answer was created in April 2015, there is a new version of the Dashboard sample that provides a very small framework for creating JavaScript visualizations of Live Datamart query results that uses Highcharts.JS rather than D3. There is also a document called TIBCO Live Datamart JavaScript Dashboard Sample: A Best Practices Guide explaining how that Dashboard sample is structured and how to add visualizations to it.
Disclosure/Disclaimer: I am an employee of TIBCO Software, Inc. Opinions expressed here are my own and not TIBCO's.

- 105
- 9
-
I've been looking at some the samples that StreamBase has, where they have several files including: app.js app.model.js Visualization.js... I am not understanding how these code coordinate with each other. I have written my code from scratch using your answer, but I'm having trouble understanding the way these examples are coded. – Dan K. Apr 10 '15 at 15:55
-
1Dan -- Maybe say more about your trouble understanding, or ask a specific question? The examples are not tiny, and I suppose you could be having trouble with any number things but it's not easy for me to guess what. – sbarber2 Apr 12 '15 at 14:16
-
Understood. The solution you gave up there is continuous query correct? Once the connection is established, the subscription will listen to the table and insert/delete/update when called? – Dan K. Apr 14 '15 at 15:59
-
Right, the query is continuous -- technically snapshot and continuous -- though that sample is only handling inserts as coded. – sbarber2 Apr 15 '15 at 16:34
-
It's also possible to directly use the subscribe and unsubscribe methods of the LiveView.Connection class to use callbacks, if you are not partial to the use of then(), which is a Promise [http://modernjavascript.blogspot.com/2013/09/promise-patterns.html]. – sbarber2 Apr 15 '15 at 16:45