new Connection()
LiveView Connection constructor. This constructor is internal to LiveView and cannot/should not be
instantiated directly. Calls to LiveView.connect() will create an appropriate Connection and return a
Connection object as a reference to the connection.
Members
(static, readonly) CONNECTION_STATUS :String
Properties:
Name | Type | Description |
---|---|---|
CLOSED |
String | The connection is closed. |
CLOSING |
String | The connection is in the process of closing. Most likely, it is waiting on resource clean-up and/or server confirmation of closure. |
OPEN |
String | The connection is open. |
OPENING |
String | The connection is in the process of opening. Most likely, it is waiting for the server to acknowledge connection. |
ERROR |
String | Something went wrong with the connection. A description of the cause should be available via the promise rejection handler or onError callback function of the error-causing function call. |
Type:
- String
id :String
The unique identifier for this connection. Its value is automatically set upon successful connection.
Type:
- String
onClose :function
Callback function to invoke upon closure of the connection (whether in error or as expected). The callback
will be passed an object containing two or three fields: connection, actor, and (optionally) error. The
connection field will be the
Connection
that was closed. The actor field will either
be "client" or "server" depending on whether the client or server initiated the closing of the connection.
The error field (if set) is an Error
. The presence of the error field indicates an
error took place and the connection was closed as a result.
Type:
- function
status :LiveView.Connection.CONNECTION_STATUS
The connection status for this connection.
Type:
url :String
The URL to which this connection is made.
Type:
- String
username :String
The username used for authenticating with the LiveView server. Its value is automatically set upon successful
connection.
Type:
- String
Methods
addAlertRule(alertRule, settingsopt) → {Promise.<Object>}
Adds an AlertRule to the LiveView server.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
alertRule |
LiveView.AlertRule | The new AlertRule to add. Note: if an id value is specified for the AlertRule, it will be honored by the server. However, if an AlertRule already exists on the server with the provided id, that alert rule will be overwritten by the rule being sent. It is recommended that the id field be left undefined when adding a rule so that the server will assign an appropriate id. | |||||||||||||||||
settings |
Object |
<optional> |
An object containing the optional parameters for addAlertRule.
Properties
|
Returns:
-- Promise representing the result of addAlertRule function. Upon success, the promise resolution handler is passed an object with field: rule. The rule field will be the
AlertRule
as it was added by the LiveView server. Note that the server may modify the "id" field in the process. If adding the alert rule fails, the promise will be rejected and the rejection handler will be passed an Error
object with details about what went wrong.
- Type
- Promise.<Object>
checkPermissions(listOfPermission, settingsopt) → {Promise.<Object>}
Checks whether the authenticated user has the specified permissions. This method always returns true for each permission when authentication is disabled.
Example
// Read Permission documentation for available type and actions;
// Constructor values can be provided to Permission like
// new LiveView(type, action, instance)
// If anything is not provided, it is assigned "*" in the above order
var permission = new LiveView.Permission(LiveView.Permission.TYPE.ALERT);
var allPermissions = []; // Permissions should be put in an array before using the checkPermissions
allPermissions.push(permission);
lvConnection.checkPermissions(allPermissions).then(
function(result){
console.log(result[0]) // since we have only one permission, the first response from the list is enough
},
function(error) {
console.log(error)
}
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
listOfPermission |
Object | An object containing Permission that details the permissions to check for the authenticated user. |
|||||||||||||||||
settings |
Object |
<optional> |
And object containing the optional parameters for checkPermissions.
Properties
|
Returns:
-- Promise representing the result of the checkPermissions function. Upon success, the promise resolution handler is passed a list of booleans indicating if the user has given permissions or not. If fetching the checkPermissions fails, the promise will be rejected and the rejection handler will be passed an
Error
object with details about what went wrong.
- Type
- Promise.<Object>
close(settingsopt) → {Promise.<void>}
Closes this connection cleanly, canceling all active queries running via this connection.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
settings |
Object |
<optional> |
Object that defines callbacks and callback context for handling connection closure.
Properties
|
Returns:
-- Promise representing the result of the close function. Once resources have been cleaned and the server has acknowledged closure, the promise will resolve with no arguments. If there is an error, the promise will be rejected and the rejection handler function will be passed an
Error
object containing details about what went wrong.
- Type
- Promise.<void>
deleteAlertRule(alertRuleId, settingsopt) → {Promise.<Object>}
Deletes an existing AlertRule at the LiveView server. Note this function will succeed even if the server has no record of an AlertRule with the provided alertRuleId.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
alertRuleId |
Number | The id of the AlertRule to delete. | |||||||||||||||||
settings |
Object |
<optional> |
An object containing the optional parameters for deleteAlertRule
Properties
|
Returns:
-- Promise representing the result of the deleteAlertRule function. Upon success, the promise resolution handler is passed an object containing field: id. The id field contains the id of the AlertRule that was deleted. If deleting the alert rule fails, the promise will be rejected and the rejection handler will be passed an
Error
object with details about what went wrong.
- Type
- Promise.<Object>
deleteRows(tableName, predicate, settingsopt) → {Promise.<Object>}
Performs a deletion query. This function tells the LiveView server to remove all rows from the provided table
that satisfy the conditions specified in the predicate. If no predicate is given, or if the predicate is an
empty string, then all rows in the given table will be removed. Note that the operation will not return the
rows that were removed. A separate query on the same table that monitors delete events can be used to monitor
which rows are removed.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tableName |
String | The name of the table upon which the deletion query will be performed. | |||||||||||||||||
predicate |
String | The predicate string that defines the conditions to use when determining whether or not to remove a row from the table. See the "LiveQL Reference" guide in the LiveView documentation for more details on how to construct predicate strings. | |||||||||||||||||
settings |
Object |
<optional> |
Object containing the optional settings for the delete function.
Properties
|
Returns:
-- Promise representing the result of the deleteRows function. On success, the promise resolution handler function will be invoked with no arguments. If there is an error, the promise will be rejected and the rejection handler function will be passed an
Error
object containing details about what went wrong.
- Type
- Promise.<Object>
execute(query, settingsopt) → {Promise.<Object>}
Performs a one-time execution of a query. This is an easy way to quickly get table data without having to set
up a query subscription. Technically, this call subscribes to a snapshot-only query and buffers results until
the end-snapshot event is received. Once the end-snapshot event is received, query resources are cleaned and
the query schema and buffered result data are returned via promise resolution and/or the onSuccess callback
function.
Example
//First connect to LiveView
var lvConnection;
LiveView.connect({url: '/lv/client'}).then(
function(connection){
//once connected, keep the reference to the connection and execute queries
lvConnection = connection;
executeQueries();
}
);
function executeQueries(){
//With Promises
lvConnection.execute(
new LiveView.Query('SELECT * FROM ItemsSales WHERE lastSoldPrice > 100')
)
.then(
function(result){
console.log('Query execution using promise/deferred finished');
console.log('Got schema:');
console.log(result.schema);
console.log('Got data:');
console.log(result.data);
},
function(error){
console.log('Something went wrong: ' + error.message);
}
);
//With Callbacks
lvConnection.execute(
new LiveView.Query('SELECT * FROM ItemsSales WHERE lastSoldPrice > 100'),
{
context: window,
onSuccess: function(result){
console.log('Query execution using callbacks finished');
console.log('Got schema:');
console.log(result.schema);
console.log('Got data:');
console.log(result.data);
},
onError: function(error){
console.log('Something went wrong: ' + error.message);
}
}
);
}
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
query |
LiveView.Query | Defines the query to perform. | |||||||||||||||||||||||||
settings |
Object |
<optional> |
Object containing the optional settings for query execution.
Properties
|
Returns:
-- Promise representing the result of the execute function. On success, the promise resolution handler function will be passed an object with two fields: schema and data. The schema field is a
Schema
that defines the query's schema. The data field contains the query results as an array of tuples in the order they were returned by the query. If there is an error, the promise will be rejected and the rejection handler function will be passed an Error
object containing details about what went wrong. When a new row is added to the query execution's result set, the promise's progress handler will be passed an object with field: tuple. The tuple field is the Tuple
that was added to the query result set. If there is an error, the promise will be rejected and the rejection handler function will be passed an Error
object containing details about what went wrong.
- Type
- Promise.<Object>
getAlertGroups(settingsopt) → {Promise.<Object>}
Gets alert group names.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
settings |
Object |
<optional> |
An object containing the optional parameters for getAlertGroups
Properties
|
Returns:
-- Promise representing the result of the getAlertGroups function. Upon success, the promise resolution handler is passed an array containing the alertgroups that were fetched. If fetching the alert groups fails, the promise will be rejected and the rejection handler will be passed an
Error
object with details about what went wrong.
- Type
- Promise.<Object>
getAlertRules(settingsopt) → {Promise.<Object>}
Gets all alert rules for the specified owner. If no owner is specified, the function fetches rules for the current user.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
settings |
Object |
<optional> |
An object containing the optional parameters for getAlertRules.
Properties
|
Returns:
-- Promise representing the result of the getAlertRules function. Upon success, the promise resolution handler is passed an object with field: rules. The rules field will be an array containing the
LiveView.AlertRule
s that were fetched. If fetching the alert rules fails, the promise will be rejected and the rejection handler will be passed an Error
object with details about what went wrong.
- Type
- Promise.<Object>
getStreams(settingsopt) → {Promise.<Object>}
Get information about the input and/or output streams at a given SB URI. An incorrect inputStream or
outputStream name will result in getting an empty object. If detailed error messages are required use
getStreamSchemas
.
Example
//Log all SB stream names to console
lvConnection.getStreams().then(
function(result){
console.log('Input Streams:');
Object
.keys(result.inputStreams)
.forEach(function(inStreamName){
console.log(inStreamName);
});
console.log('Output Streams:');
Object
.keys(result.outputStreams)
.forEach(function(outStreamName){
console.log(outStreamName);
});
}
);
//Pretty-print the meta-data (including schema) for the ItemsSales.DataIn stream
lvConnection.getStreams({inputStreamFilter: ['ItemsSales.DataIn'], outputStreamFilter: [], includeSchemas: true}).then(
function(result){
console.log(JSON.stringify(result.inputStreams, null, ' '));
}
);
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
settings |
Object |
<optional> |
An object containing optional parameters for the getStreams function
Properties
|
Returns:
-- Promise representing the result of the getStreams function. Upon success, the promise resolution handler is passed an object with with two fields: inputStreams and outputStreams. The inputStreams and outputStreams fields will be a key-value object map where the key is the stream name and the value is an object containing meta-data about the stream. Meta-data for both input and output streams will contain a "schema" field of type
Schema
, if the includeSchemas flag was set to true. If getting the streams fails, the promise will be rejected and the rejection handler will be passed an Error
object with details about what went wrong.
- Type
- Promise.<Object>
getStreamSchemas(inputStream, outputStreamopt, settingsopt) → {Promise.<Object>}
Gets the schemas for tuples sent to the identified input stream and received from the identified output
stream. Use of fully-qualified stream names is encouraged. If a fully-qualified stream name is not used,
it will be assumed that the stream exists in the default container. Typically, however, application streams
will not exist in the default container, which will likely result in problems.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
inputStream |
String | The name of the input stream. | |||||||||||||||||||||
outputStream |
String |
<optional> |
The name of the output stream. If not provided, the resulting outputSchema will be an empty object. | ||||||||||||||||||||
settings |
Object |
<optional> |
An object containing the parameters for getStreamSchemas.
Properties
|
Returns:
-- Promise representing the result of the getStreamSchemas function. Upon success, the promise resolution handler is passed an object with fields: inputSchema and outputSchema. The inputSchema field will be a
Schema
that describes the schema that should be applied to tuples being sent to the specified inputStream. The outputSchema field will be a Schema
that describes the schema that applies to tuples being received via the specified outputStream. If getting the stream schemas fails, the promise will be rejected and the rejection handler will be passed an Error
object with details about what went wrong.
- Type
- Promise.<Object>
getTables(settingsopt) → {Promise.<Object>}
Performs a one-time get of table metadata for the (optionally) specified tables.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
settings |
Object |
<optional> |
Object containing the settings for getting table metadata
Properties
|
Returns:
-- Promise representing the result of the getTables function. On success, the promise resolution handler function will be passed an object with field: tables. The tables field is an array of
Table
objects. If there is an error, the promise will be rejected and the rejection handler function will be passed an Error
object containing details about what went wrong.
- Type
- Promise.<Object>
parseQuery(query, settingsopt) → {Promise.<LiveView.QueryProperties>}
Validates a query and (if valid) returns various information describing the characteristics of the query.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
query |
LiveView.Query | String | A Query object or query String to be parsed. |
|||||||||||||||||||||
settings |
Object |
<optional> |
Object containing the settings for parsing the query
Properties
|
Returns:
-- Promise representing the result of the parseQuery function. On success, the promise resolution handler function will be passed an object with field: queryProperties. The queryProperties field is a
QueryProperties
object that contains information about the parsed query. If there is an error (perhaps because the query failed to validate), the promise will be rejected and the rejection handler function will be passed an Error
object containing details about what went wrong.
- Type
- Promise.<LiveView.QueryProperties>
sendTuple(tuple, inputStream, outputStream, settingsopt) → {Promise.<Object>}
Sends a tuple to the specified stream. Use of fully-qualified stream names is encouraged. If a fully-
qualified stream name is not used, it will be assumed that the stream exists in the default container.
Typically, however, application streams will not exist in the default container, which will likely result in
problems.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tuple |
LiveView.Tuple | The tuple object to send. | |||||||||||||||||||||||||
inputStream |
String | The name of the input stream to send the tuple to. | |||||||||||||||||||||||||
outputStream |
String | The name of the output stream that the resultant tuple should be retrieved from. This can be null if no response is desired or expected. | |||||||||||||||||||||||||
settings |
Object |
<optional> |
An object containing the parameters for sendTuple
Properties
|
Returns:
-- Promise representing the result of the sendTuple function. Upon success, the promise resolution handler is passed an object with field: tuple. The tuple field will be the resulting output tuple if an outputStream was specified. Otherwise, the tuple field will be null. If sending the tuple fails, the promise will be rejected and the rejection handler will be passed an
Error
object with details about what went wrong.
- Type
- Promise.<Object>
subscribe(query, settingsopt) → {Promise.<Object>}
Performs a continuous LiveView query that will be updated with any changes in query results.
Example
//First connect to LiveView
var lvConnection;
LiveView.connect({url: '/lv/client'}).then(
function(connection){
//once connected, keep the reference to the connection and run queries
lvConnection = connection;
runQueries();
}
);
function runQueries(){
lvConnection.subscribe(
new LiveView.Query('SELECT * FROM ItemsInventory WHERE priceMax > 20'),
{
onSnapshotStart: function(event){
console.log('Snapshot started for query ' + event.subscription.id);
console.log('The query schema is:');
console.log(event.schema);
},
onInsert: function(event){
console.log('Query ' + event.subscription.id + ' got new data.');
console.log('The new tuple is:');
console.log(event.tuple);
},
onUpdate: function(event){
console.log('Query ' + event.subscription.id + ' updated data for tuple ' + event.tuple.id);
console.log('The updated tuple data is:');
console.log(event.tuple.fieldMap);
},
onDelete: function(event){
console.log('Query ' + event.subscription.id + ' deleted tuple ' + event.tuple.id);
},
onSnapshotEnd: function(event){
console.log('Snapshot ended for query ' + event.subscription.id);
},
onError: function(error){
console.log('There was an error while running query ' + event.subscription.id);
console.log('ERROR:');
console.log(error);
}
}
)
.then(
function(result){
console.log('Query subscription success');
console.log('QuerySubscription for future reference:');
console.log(result.subscription);
console.log('Got schema:');
console.log(result.schema);
},
function(error){
console.log('Something went wrong: ' + error.message);
}
);
}
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
query |
LiveView.Query | Defines the query to perform. | |||||||||||||||||||||||||||||||||||||||||
settings |
Object |
<optional> |
Object containing the optional settings for query subscription.
Properties
|
Returns:
-- Promise representing the result of the subscribe function. On success, the promise resolution handler function will be passed an object with field: subscription. The subscription field is the
QuerySubscription
that represents the created subscription. If there is an error, the promise will be rejected and the rejection handler function will be passed an Error
object containing details about what went wrong.
- Type
- Promise.<Object>
unsubscribe(querySubscription, settingsopt) → {Promise.<Object>}
Unsubscribes from an active QuerySubscription.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
querySubscription |
LiveView.QuerySubscription | The active QuerySubscription to close | |||||||||||||||||
settings |
Object |
<optional> |
Object containing the settings for unsubscribing from the query.
Properties
|
Returns:
-- Promise representing the result of the unsubscribe function. On success, the promise resolution handler function will be passed an object with field: subscription. The subscription field is the
QuerySubscription
that successfully unsubscribed. If there is an error, the promise will be rejected and the rejection handler function will be passed an object containing fields: subscription and error. The subscription field is the QuerySubscription
that failed to unsubscribe. The error field is an Error
with details about what went wrong.
- Type
- Promise.<Object>
unsubscribeAll(settingsopt) → {Promise.<Object>}
Unsubscribes from all active query subscriptions.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
settings |
Object |
<optional> |
Object containing the settings for unsubscribing.
Properties
|
Returns:
-- Promise representing the result of the unsubscribeAll function. On success (i.e. when all subscriptions have successfully been unsubscribed), the promise will resolve with no arguments. If there is an error, the promise will be rejected and the rejection handler function will be passed an
Error
object containing details about what went wrong.
- Type
- Promise.<Object>
updateAlertRule(alertRule, settingsopt) → {Promise.<Object>}
Updates an existing AlertRule at the LiveView server.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
alertRule |
LiveView.AlertRule | The updated version of the AlertRule. The id field must be set in order to successfully update the rule. If the id field is not set, or if the server has no rule with the specified id, the passed rule will be added. | |||||||||||||||||
settings |
Object |
<optional> |
An object containing the optional parameters for updateAlertRule
Properties
|
Returns:
-- Promise representing the result of the updateAlertRule function. Upon success, the promise resolution handler is passed an object with field: rule. The rule field will be the
AlertRule
that was updated at the LiveView server. If updating the alert rule fails, the promise will be rejected and the rejection handler will be passed an Error
object with details about what went wrong.
- Type
- Promise.<Object>
validateAlertRule(alertRule, settingsopt) → {Promise.<Object>}
Validates an AlertRule at the LiveView server.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
alertRule |
LiveView.AlertRule | The AlertRule to validate. | |||||||||||||||||
settings |
Object |
<optional> |
An object containing the optional parameters for validateAlertRule
Properties
|
Returns:
-- Promise representing the result of the validateAlertRule function. If the rule validates successfully, the promise will resolve and the promise resolution handler function is passed an object containing field: rule. The rule field will be the
AlertRule
that was successfully validated. If the rule is invalid, the promise will be rejected and the rejection handler will be passed an Error
object containing details about what went wrong.
- Type
- Promise.<Object>