Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Data storage in ThingWorx can take place three (3) manners :
Before beginning with above three topics one must also understand concept of :
What is InfoTable ?
An InfoTable is zero indexed, ordered array of javaScript objects which expose same properties. Since an InfoTable is an Array of Objects, it can also be thought of as a table where the array entries are rows and the object properties of each object in the array are the columns.
For example :
var people = [
{
“name” : “Ravi”,
“city” : “Mumbai”
},
{
“name” : “Mohit”,
“city” : “New Delhi”
}
];
As you can see InfoTables only contains the same type of object.This is achieved using another ThingWorx specific mechanism called Data Shape
What is Data Shape ?
A DataShape is a specification of the required property names and return types each property of a JavaScript “Object” must have to be added to an InfoTable.
DataShapes also contain other metadata about a property that is useful for formatting and displaying the InfoTable in a tabular format or Grid.
They are essentially a schema mechanism for defining the required fields of a Thing in ThingWorx.
Now that we have covered InfoTables and DataShapes, let us move towards core concepts of data storage
1. Data Tables
A ThingWorx Data Table Thing is similar to a standard relational database table. However, a Data Shape defines the columns of a Data Table. Data Tables can be used to store data in a ThingWorx application.
The Configuration tab for a Data Table allows you to define additional table indexes. This is similar to a relational database table, where in addition to the primary key (the primary key is defined in the Data Shape), you need to query the table based on other fields. You should create an index for each set of filter criteria commonly used. This will have a significant impact on query performance.
2. Streams
Streams represent time series data. Therefore, each Stream has a timestamp plus additional fields. A ThingWorx Stream is a list of activities from Things or data associated with Things.
A stream can be thought of as a table structure with certain predefined fields and any number of user-defined fields. User-defined fields are defined using DataShape.
3. Value Streams
ThingWorx Value Streams also provide time series information about a Thing’s property values.
Value streams are similar to streams in terms of their end results however there is some noteworthy difference between Stream and Value Stream in manner in which data gets written and returned.
Streams are independent data stores and can access data continuously:
- Querying single column value returns entire row
- Remain most beneficial for non-Thing-driven models
- Scipts are required to write data to Streams
For example : You can set up a timer and subscribe to the timer event and every time timer emits the event we can log data in stream.
Value Streams store data from associated Thing’s property :
- Querying Thing’s property data only returns values for that property
- Scripts not required to write Thing property data to its Value Stream
- Most useful for Thing-driven models
Note : Data gets stored in the configured persistence provider.
Good Work Siddarath.
Could we add some information to this article? That would be that Infotables are by default in-memory objects, that don't resist a server restart if they are not persisted, and all the other options (DataTable, Stream and ValueStream) are objects which store the data on disk.
By not storing the data in-memory if you make a query on a DataTable / Stream / VS this will access the disk, while this won't happen for an Infotable.
This information should be considered in the initial stages when you are doing application development.
Great write up Siddarath.
There is also a great guide on the Developer Portal called "Data Storage Guide" that I've found helpful.