Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • DataModel
  • ThingModel
  • AppModel

Model lifecycle consists of three steps

  • Definition - Models are defined either using TQLStudio Model Editor or any IDE of your choice. 
    Modeling Language (Thing Definition Language) is essential to define models.
  • Deploy - As part of a deployable unit within TQLEngine's package file. Models definitions are made part of SffTqlFacet Facet type.
  • Query - Querying of model consists of CRUD as well as Subscription (and notification).

Image RemovedSee Models for details.

In TQL Model development is a three step process -

  1. Definition
  2. Deploy (compilation)
  3. Queries (instantiation, update, delete, subscription)

See also lifecycle of models.

Image Added

Model Instances

Once models are defined and deployed their schematic layout is persisted in Storage (TQL Cache) the meta structure of the model definition is stored in memory. (If A-Stack shuts down and restart, the model definitions will be reloaded. The but model instance data will persist.)

Before Find queries can find anything from the models, they must be instantiated, or populated with data. The result of model instantiation is called Model Instances. Multiple model instances can be created from the same model (definition). Model instance data is persisted in the storage (TQLCache), as defined at the time of the deployment. Note that

...

Note

even though models are persisted in SQL type of storage that data is highly unstructured and stored in proprietary format.

Before Models can be queried using Find - Models must be initialized or populated with data. The result of model creation is called Model Instances.

For example:

 

Attribute values (Value)

Attribute known values (Known)

Version number of each attribute value?

Timestamp of ____?

Sid

...

Storage and update of model instance data:

Only the latest version of the value and known value are stored.

The version number will be kept

Even though A-Stack uses SQL type of database technology to persist model instances, they are stored in a schema-less way, not in a relational format. This preserves the the performance at scale.

For example: Here is the definition of a ThingModel - PhidgetSensorModel that combines PhidgetSensorFacet. 

Definition

Code Block
languageruby
themeEmacs
titlePhidgetSensor Thing Model
linenumberstrue
#
ThingFacet(Name: "PhidgetSensorFacet"):
  Integer(Name: "SensorValue", Update: "auto", KnownBy: "PhidgetSensorAction")
  String(Name: "SensorURL", Default: "phid://")
  String(Name: "SensorInterfaceIndex")
  String(Name: "SensorType")
  String(Name: "SensorInterfaceType")
  String(Name: "SensorValueFormat")
  String(Name: "Simulated")
ThingModel(Name: "PhidgetSensorModel", Combines: "PhidgetSensorFacet"):
  Sid(Name: "phidId")

Create model instances

The model instances of PhidgetSensorModel is created using a Create TQL Query. 

Code Block
languageruby
themeEmacs
titleCreate PhidgetSensor ThingModel Instance
linenumberstrue
#
Query: 
  Create: 
    PhidgetSensors: 
      SensorURL: phid:// 
      SensorType: Rotation 
      SensorInterfaceType: PhidgetInterfaceKit 
      SensorValueFormat: Raw 
      SensorInterfaceIndex: 0 
      SensorValue(value: "$Null()", version: "1");
      Simulated: true

The result of model instance creation is below.

Note that there is Status returned for every attribute that gets created.

Code Block
languageruby
themeEmacs
titleCreate PhidgetSensor ThingModel Instance Result
linenumberstrue
#
Create(Status: "Success"):
  PhidgetSensors: 
    phidId: KNUBPHLOAAAAUAABA6EJCI75
    SensorValue(Status: "Success+Created:1:1457740291438;", Value: "", Version: "1")
    SensorURL(Status: "Success+Created:1:1457740291442;", Value: "phid://", Version: "1")
    SensorInterfaceIndex(Status: "Success+Created:1:1457740291443;", Value: "0", Version: "1")
    SensorType(Status: "Success+Created:1:1457740291444;", Value: "Rotation", Version: "1")
    SensorInterfaceType(Status: "Success+Created:1:1457740291444;", Value: "PhidgetInterfaceKit", Version: "1")
    SensorValueFormat(Status: "Success+Created:1:1457740291445;", Value: "Raw", Version: "1")
    Simulated(Status: "Success+Created:1:1457740291445;", Value: "true", Version: "1")

Find Model Instances

After model instances are created, you can read them using Find Query with constraints.

Code Block
languageruby
themeEmacs
titleFind PhidgetSensor ThingModel Instance
linenumberstrue
#
Query: 
  Find format: "all"):
    PhidgetSensors: 
      SensorURL(ne : "")

Find Query Result

Code Block
languageruby
themeEmacs
titleFind PhidgetSensor ThingModel Instance
linenumberstrue
#Find(Status: "Success", Format: "all"):
	Result: 
		PhidgetSensors(QName: "SimpleModel.MyModels.PhidgetSensors"):
			phidId: KNUBPHLOAAAAUAABA6EJCI75 
			SensorValue(Value: "", Known: "60", Version: "1", Timestamp: "1457740291438", DateTime: "2016-03-11 15:51:31.438", QName: "SimpleModel.MyModels.PhidgetSensors.SensorValue", FName: "SensorValue")
			SensorURL(Value: "phid://", Known: "phid://", Version: "1", Timestamp: "1457740291442", DateTime: "2016-03-11 15:51:31.442", QName: "SimpleModel.MyModels.PhidgetSensors.SensorURL", FName: "SensorURL")
			SensorInterfaceType(Value: "PhidgetInterfaceKit", Known: "PhidgetInterfaceKit", Version: "1", Timestamp: "1457740291444", DateTime: "2016-03-11 15:51:31.444", QName: "SimpleModel.MyModels.PhidgetSensors.SensorInterfaceType", FName: "SensorInterfaceType")
			Simulated(Value: "true", Known: "true", Version: "1", Timestamp: "1457740291445", DateTime: "2016-03-11 15:51:31.445", QName: "SimpleModel.MyModels.PhidgetSensors.Simulated", FName: "Simulated")
			SensorInterfaceIndex(Value: "0", Known: "0", Version: "1", Timestamp: "1457740291443", DateTime: "2016-03-11 15:51:31.443", QName: "SimpleModel.MyModels.PhidgetSensors.SensorInterfaceIndex", FName: "SensorInterfaceIndex")
			SensorType(Value: "Rotation", Known: "Rotation", Version: "1", Timestamp: "1457740291444", DateTime: "2016-03-11 15:51:31.444", QName: "SimpleModel.MyModels.PhidgetSensors.SensorType", FName: "SensorType")
			SensorValueFormat(Value: "Raw", Known: "Raw", Version: "1", Timestamp: "1457740291445", DateTime: "2016-03-11 15:51:31.445", QName: "SimpleModel.MyModels.PhidgetSensors.SensorValueFormat", FName: "SensorValueFormat")


Note
iconfalse

The following system generated tags are for each attribute: 

Include Page
System generated tags for attributes
System generated tags for attributes

Go to page

Status: This is a transient attribute returned as part of the result of TQL Create/Save, Update and Delete operations. It is not persisted.