Scandit.Db

Cloud DB is a distributed document-oriented database that is automatically synchronized between all connected devices and Scandit Cloud. This replicated database can be accessed through the Web Dashboard, the REST API and the Flow Mobile API. With Cloud DB, data is always available locally on the devices and can be accessed by activities even when there is no network connection and so enables fast, consistent queries and updates.

The module contains all objects which are defined in storage configuration, on the web dashboard.

Object classes are based on Scandit.Db.BaseModel and accessible as Scandit.Db.MODEL_NAME, where MODEL_NAME is the name of the defined model.

Classes

BaseModel

Methods

(static) getSyncState(direction: string): Promise

Current database synchronisation state

Parameters:
Name Type Description
direction string

Synchronisation direction. Possible values: PULL or PUSH

Returns:
Promise

Promise which is resolved with an object containing the sync direction and state. Possible values: RUNNING, IDLE, OFFLINE, STOPPED

Examples
  • JavaScript
  • ES6
Scandit.Db.getSyncState('PULL').then(function(syncState) {
  console.log(syncState);
});
Scandit.Db.getSyncState('PULL').then(syncState => {
  console.log(syncState);
});

(static) off(arg: (string | function))

Removes an event handler. Possible events: sync, syncStateChange

Parameters:
Name Type Description
arg string | function

Event name or callback function

Examples
  • JavaScript
  • ES6
Scandit.Db.off('sync');
Scandit.Db.off('sync');

(static) on(event: string, callback: function)

Binds event handlers to database related events. Possible events: sync, syncStateChange

Parameters:
Name Type Description
event string

Event name

callback function

Event callback

Examples
  • JavaScript
  • ES6
Scandit.Db.on('sync', function(syncProgress) {
  console.log(syncProgress);
});
Scandit.Db.on('sync', function(syncProgress) {
  console.log(syncProgress);
});

Type Definitions

Attachment

Properties:
Name Type Description
url string

Path to the attachment

mimeType string

mimeType of the attachment

See:

Query

Database query object.

Type:
  • object
Properties:
Name Type Description
FIELD_NAME string

the name of the object field to be queried

Properties
Name Type Description
QUERY_OPERATOR string
  • possible values for the operator: $eq (equals), $text (fulltext search)
  • the value is the value to be queried
Examples
Query that will match objects where the name is '8mm Flat Metric Washer' and the kind is 'product'
  • JavaScript
  • ES6
var query = {
  name: {
    $eq: '8mm Flat Metric Washer'
  },
  kind: {
    $eq: 'product'
  }
};
const query = {
  name: {
    $eq: '8mm Flat Metric Washer'
  },
  kind: {
    $eq: 'product'
  }
};

Events

sync

Sync event

Fires while the database is syncing (PULL or PUSH). Returns an object with the progress, containing the pulled/pushed count of changes (pull/push) and the total number of changes to be pulled/pushed (pullTotal/pushTotal) (as integers)

Examples
  • JavaScript
  • ES6
Scandit.Db.on('sync', function(syncProgress) {
  console.log(syncProgress);
});
Scandit.Db.on('sync', syncProgress => {
  console.log(syncProgress);
});

syncStateChange

Sync state change event

Returns an object with direction, newState and previousState

Properties:
Name Type Description
direction string

Possible directions: PULL, PUSH

newState string

Possible states: RUNNING, IDLE, OFFLINE, STOPPED

previousState string

Possible states: RUNNING, IDLE, OFFLINE, STOPPED

Examples
  • JavaScript
  • ES6
Scandit.Db.on('syncStateChange', function(syncState) {
  console.log(syncState);
});
Scandit.Db.on('syncStateChange', syncState => {
  console.log(syncState);
});