SlideShare una empresa de Scribd logo
1 de 50
Copyright © 2016 M/Gateway Developments Ltd
EWD 3 Training Course
Part 19
Accessing a Global Storage
Database from JavaScript: the
cache.node APIs
Rob Tweed
Director, M/Gateway Developments Ltd
Twitter: @rtweed
Copyright © 2016 M/Gateway Developments Ltd
cache.node
• The cache.node interface module allows
you to access a Caché database from
JavaScript
Copyright © 2016 M/Gateway Developments Ltd
NodeM
• The NodeM module is an Open Source
emulation of cache.node, allowing the
GT.M database to be accessed identically
from JavaScript
– https://github.com/dlwicksell/nodem
Copyright © 2016 M/Gateway Developments Ltd
ewd-redis-globals
• The Redis-based ewd-redis-globals
implementation of Global Storage includes
an implementation of the cache.node
APIs, allowing the database to be
accessed identically from JavaScript
– https://github.com/robtweed/ewd-redis-globals
Copyright © 2016 M/Gateway Developments Ltd
cache.node, NodeM &
ewd-redis-globals APIs
When accessed in a QEWD
application:
this.db.{{someFunctioName}}()
Copyright © 2016 M/Gateway Developments Ltd
Loading and Initialising the
Interface Modules
These steps are done for you
automatically by QEWD
Here’s how to do it manually, eg
if you're creating a standalone
test-harness…
Copyright © 2016 M/Gateway Developments Ltd
cache.node APIs
Loading cache.node:
var interface = require('cache');
var db = new interface.Cache();
Copyright © 2016 M/Gateway Developments Ltd
cache.node APIs
Opening connection to Caché :
db.open({
path: '/opt/cache/mgr',
username: '_SYSTEM',
password: 'SYS',
namespace: 'USER',
charset: 'UTF-8',
lock: 0
});
Copyright © 2016 M/Gateway Developments Ltd
cache.node APIs
Closing connection to Caché:
var ok = db.close();
Copyright © 2016 M/Gateway Developments Ltd
NodeM (GT.M) APIs
Loading NodeM:
var interface = require('nodem');
var db = new interface.Gtm();
Copyright © 2016 M/Gateway Developments Ltd
NodeM APIs
Opening connection to GT.M:
db.open();
Copyright © 2016 M/Gateway Developments Ltd
NodeM APIs
Opening connection to GT.M:
db.open();
Thereafter, all APIs are identical to those used with cache.node
Copyright © 2016 M/Gateway Developments Ltd
NodeM APIs
Closing connection to GT.M:
var ok = db.close();
ie: Identical to cache.node
Copyright © 2016 M/Gateway Developments Ltd
ewd-redis-globals APIs
Loading ewd-redis-globals:
var interface = require('ewd-redis-globals');
var db = new interface();
Copyright © 2016 M/Gateway Developments Ltd
Opening connection to Redis / ewd-redis-globals:
db.open();
ewd-redis-globals APIs
Copyright © 2016 M/Gateway Developments Ltd
Thereafter, all APIs are identical to those used with cache.node
Opening connection to Redis / ewd-redis-globals:
db.open();
ewd-redis-globals APIs
Copyright © 2016 M/Gateway Developments Ltd
Closing connection to Redis / ewd-redis-globals:
var ok = db.close();
ie: Identical to cache.node
ewd-redis-globals APIs
Copyright © 2016 M/Gateway Developments Ltd
Setting up a test harness
• Ready to use example for Caché in
QEWD:
– C:qewdnode_modulesqewdexampletest.js
– Needs editing to match your Caché (or other
database) configuration
• Use previous slides for GT.M and Redis
Copyright © 2016 M/Gateway Developments Ltd
Edit test.js
var interface = require('cache');
var db = new interface.Cache();
console.log('db: ' + JSON.stringify(db));
// Change these parameters to match your GlobalsDB or Cache system:
var ok = db.open({
path: '/opt/cache/mgr',
username: '_SYSTEM',
password: 'SYS',
namespace: 'USER'
});
console.log('ok: ' + JSON.stringify(ok));
console.log(db.version());
var node = {
global: 'rob',
subscripts: [1],
data: 'hello'
};
db.set(node);
var result = db.get(node);
console.log(JSON.stringify(result));
db.close();
Copyright © 2016 M/Gateway Developments Ltd
Edit test.js
var interface = require('cache');
var db = new interface.Cache();
console.log('db: ' + JSON.stringify(db));
// Change these parameters to match your GlobalsDB or Cache system:
var ok = db.open({
path: 'C:InterSystemsCache2015-2mgr',
username: '_SYSTEM',
password: 'SYS',
namespace: 'USER'
});
console.log('ok: ' + JSON.stringify(ok));
console.log(db.version());
var node = {
global: 'rob',
subscripts: [1],
data: 'hello'
};
db.set(node);
var result = db.get(node);
console.log(JSON.stringify(result));
db.close();
Copyright © 2016 M/Gateway Developments Ltd
Save as C:qewdtest.js
var interface = require('cache');
var db = new interface.Cache();
console.log('db: ' + JSON.stringify(db));
// Change these parameters to match your GlobalsDB or Cache system:
var ok = db.open({
path: 'C:InterSystemsCache2015-2mgr',
username: '_SYSTEM',
password: 'SYS',
namespace: 'USER'
});
console.log('ok: ' + JSON.stringify(ok));
console.log(db.version());
var node = {
global: 'rob',
subscripts: [1],
data: 'hello'
};
db.set(node);
var result = db.get(node);
console.log(JSON.stringify(result));
db.close();
Copyright © 2016 M/Gateway Developments Ltd
Run it
cd qewd (or on Linux / Raspberry Pi: cd /qewd )
node test
Copyright © 2016 M/Gateway Developments Ltd
Run it
cd qewd
node test
db: {}
ok: {"ok":1,"result":1,"cache_pid":2960}
Node.js Adaptor for Cache: Version: 1.1.113 (CM); Cache Version: 2015.2 build 66
4
{"global":"rob","subscripts":[1],"data":"hello","ok":1,"defined":1}
Copyright © 2016 M/Gateway Developments Ltd
One difference between test harness
and QEWD
• Test harness: invoke cache.node APIs
using:
– db.xxx()
• In QEWD worker module, they are
accessed using:
– this.db.xxx()
Copyright © 2016 M/Gateway Developments Ltd
One difference between test harness
and QEWD
• Test harness: invoke cache.node APIs
using:
– db.xxx()
db.set(node);
var result = db.get(node);
console.log(JSON.stringify(result));
db.close();
Copyright © 2016 M/Gateway Developments Ltd
One difference between test harness
and QEWD
• In QEWD worker module:
– this.db.xxx()
• Note: QEWD opens the database automatically when a worker is
started, and closes it automatically when the worker is stopped
this.db.set(node);
var result = this.db.get(node);
console.log(JSON.stringify(result));
Copyright © 2016 M/Gateway Developments Ltd
The Basic Global Storage APIs
Copyright © 2016 M/Gateway Developments Ltd
Global Storage handling APIs
Accessing global nodes:
- set
- get
- delete (kill)
Copyright © 2016 M/Gateway Developments Ltd
Defining a Global Node:
var node = {
global: 'employee',
subscripts: [123456, 'name']
};
Global Storage handling APIs
Copyright © 2016 M/Gateway Developments Ltd
Defining a Global Node:
var node = {
global: 'employee',
subscripts: [123456, 'name']
};
employee(123456,"name")
Global Storage handling APIs
Copyright © 2016 M/Gateway Developments Ltd
Accessing global nodes:
- set
node.data = 'Rob Tweed';
this.db.set(node);
Global Storage handling APIs
Copyright © 2016 M/Gateway Developments Ltd
Accessing global nodes:
- get
var value = this.db.get(node).data;
Global Storage handling APIs
Copyright © 2016 M/Gateway Developments Ltd
Accessing global nodes:
- kill
this.db.kill(node);
Global Storage handling APIs
Copyright © 2016 M/Gateway Developments Ltd
Traversing Global Subscripts
Copyright © 2016 M/Gateway Developments Ltd
Traversing global nodes:
- Iterate through subscripts
Global Storage handling APIs
Copyright © 2016 M/Gateway Developments Ltd
Traversing global nodes:
- Iterate through subscripts at a particular hierarchy level
myGlobal("a")=123
myGlobal("b","c1")="foo"
myGlobal("b","c2")="foo2"
myGlobal("d","e1","f1")="bar1"
myGlobal("d","e1","f2")="bar2"
myGlobal("d","e2","f1")="bar1"
myGlobal("d","e2","f2")="bar2"
myGlobal("d","e2","f3")="bar3"
myGlobal
"a" 123
"b"
"c2" "foo2"
"d"
"c1" "foo"
"e2"
"e1"
"f2" "bar2"
"f1" "bar1"
"f2" "bar2"
"f1" "bar1"
"f3" "bar3"
"a", "b", "d"
Global Storage handling APIs
Copyright © 2016 M/Gateway Developments Ltd
Traversing global nodes:
- Iterate through subscripts at a particular hierarchy level
myGlobal("a")=123
myGlobal("b","c1")="foo"
myGlobal("b","c2")="foo2"
myGlobal("d","e1","f1")="bar1"
myGlobal("d","e1","f2")="bar2"
myGlobal("d","e2","f1")="bar1"
myGlobal("d","e2","f2")="bar2"
myGlobal("d","e2","f3")="bar3"
myGlobal
"a" 123
"b"
"c2" "foo2"
"d"
"c1" "foo"
"e2"
"e1"
"f2" "bar2"
"f1" "bar1"
"f2" "bar2"
"f1" "bar1"
"f3" "bar3"
"e1", "e2"
Global Storage handling APIs
Copyright © 2016 M/Gateway Developments Ltd
Traversing global nodes:
- Iterate through subscripts at a particular hierarchy level
myGlobal("a")=123
myGlobal("b","c1")="foo"
myGlobal("b","c2")="foo2"
myGlobal("d","e1","f1")="bar1"
myGlobal("d","e1","f2")="bar2"
myGlobal("d","e2","f1")="bar1"
myGlobal("d","e2","f2")="bar2"
myGlobal("d","e2","f3")="bar3"
myGlobal
"a" 123
"b"
"c2" "foo2"
"d"
"c1" "foo"
"e2"
"e1"
"f2" "bar2"
"f1" "bar1"
"f2" "bar2"
"f1" "bar1"
"f3" "bar3"
"f1", "f2", "f3"
Global Storage handling APIs
Copyright © 2016 M/Gateway Developments Ltd
myGlobal("d","e2","f1")="bar1"
myGlobal("d","e2","f2")="bar2"
myGlobal("d","e2","f3")="bar3"
"f1", "f2", "f3"
Global Storage handling APIs
To achieve the following traversal:
Copyright © 2016 M/Gateway Developments Ltd
Traversing Global Node:
var node = {
global: 'myGlobal',
subscripts: ['d', 'e2', '' ]
};
myGlobal("d","e2","f1")="bar1"
myGlobal("d","e2","f2")="bar2"
myGlobal("d","e2","f3")="bar3"
"f1", "f2", "f3"
Global Storage handling APIs
Copyright © 2016 M/Gateway Developments Ltd
Traversing Global Node:
var node = {
global: 'myGlobal',
subscripts: ['d', 'e2', '' ]
};
myGlobal("d","e2","f1")="bar1"
myGlobal("d","e2","f2")="bar2"
myGlobal("d","e2","f3")="bar3"
"f1", "f2", "f3"
"seed" value to start iterator
Empty string
Global Storage handling APIs
Copyright © 2016 M/Gateway Developments Ltd
Traversing Global Node:
var node = {
global: 'myGlobal',
subscripts: ['d', 'e2', '' ]
};
var subscript = this.db.order(node).result;
// 'f1'
myGlobal("d","e2","f1")="bar1"
myGlobal("d","e2","f2")="bar2"
myGlobal("d","e2","f3")="bar3"
"f1", "f2", "f3"
Global Storage handling APIs
Copyright © 2016 M/Gateway Developments Ltd
Traversing Global Node:
var node = {
global: 'myGlobal',
subscripts: ['d', 'e2', '' ]
};
var subscript = this.db.order(node).result;
// 'f1'
subscript = this.db.order(node).result;
// 'f2' myGlobal("d","e2","f1")="bar1"
myGlobal("d","e2","f2")="bar2"
myGlobal("d","e2","f3")="bar3"
"f1", "f2", "f3"
Global Storage handling APIs
Copyright © 2016 M/Gateway Developments Ltd
Traversing Global Node:
var node = {
global: 'myGlobal',
subscripts: ['d', 'e2', '' ]
};
var subscript = this.db.order(node).result;
// 'f1'
subscript = this.db.order(node).result;
// 'f2'
subscript = this.db.order(node).result;
// 'f3'
myGlobal("d","e2","f1")="bar1"
myGlobal("d","e2","f2")="bar2"
myGlobal("d","e2","f3")="bar3"
"f1", "f2", "f3"
Global Storage handling APIs
Copyright © 2016 M/Gateway Developments Ltd
Traversing Global Node:
var node = {
global: 'myGlobal',
subscripts: ['d', 'e2', '' ]
};
var subscript = this.db.order(node).result;
// 'f1'
subscript = this.db.order(node).result;
// 'f2'
subscript = this.db.order(node).result;
// 'f3'
subscript = this.db.order(node).result;
// ''
myGlobal("d","e2","f1")="bar1"
myGlobal("d","e2","f2")="bar2"
myGlobal("d","e2","f3")="bar3"
"f1", "f2", "f3"
Global Storage handling APIs
Copyright © 2016 M/Gateway Developments Ltd
Traversing Global Node:
var node = {
global: 'myGlobal',
subscripts: ['d', 'e2', 'f2' ]
};
var subscript = this.db.order(node).result;
// 'f3'
myGlobal("d","e2","f1")="bar1"
myGlobal("d","e2","f2")="bar2"
myGlobal("d","e2","f3")="bar3"
"f3"
"seed" value to start iterator
Start from f2
Global Storage handling APIs
Copyright © 2016 M/Gateway Developments Ltd
Traversing Global Node:
var subscript = this.db.order(node).result;
// 'f3'
node is now:
{
global: 'myGlobal',
subscripts: ['d', 'e2', 'f3' ]
};
myGlobal("d","e2","f1")="bar1"
myGlobal("d","e2","f2")="bar2"
myGlobal("d","e2","f3")="bar3"
Global Storage handling APIs
Copyright © 2016 M/Gateway Developments Ltd
Traversing Global Node:
var node = {
global: 'myGlobal',
subscripts: ['d', 'e2', 'f2' ]
};
var subscript = this.db.order(node).result;
// 'f3'
subscript = this.db.order(node).result;
// '' myGlobal("d","e2","f1")="bar1"
myGlobal("d","e2","f2")="bar2"
myGlobal("d","e2","f3")="bar3"
""
Global Storage handling APIs
Empty string means no further subscripts, so traversal is complete
Copyright © 2016 M/Gateway Developments Ltd
Traversing Global Node – generic loop:
var node = {
global: 'myGlobal',
subscripts: ['d', 'e2', '' ]
};
var subscript;
do {
subscript = this.db.order(node).result;
if (subscript !== '') console.log(subscript);
}
while (subscript !== '');
myGlobal("d","e2","f1")="bar1"
myGlobal("d","e2","f2")="bar2"
myGlobal("d","e2","f3")="bar3"
"f1", "f2", "f3"
Global Storage handling APIs
Copyright © 2016 M/Gateway Developments Ltd
The APIs are low-level
• Deliberately designed to provide the basic
means of access to Global Storage and nothing
more
• They assume you understand the mechanics of
Global Storage
• Too low-level for JavaScript development
– Traversal, in particular, requires a lot of code
• However, they can be abstracted to a more
JavaScript-centric point of view
– Which is the subject of the next part of this course

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

EWD 3 Training Course Part 30: Modularising QEWD Applications
EWD 3 Training Course Part 30: Modularising QEWD ApplicationsEWD 3 Training Course Part 30: Modularising QEWD Applications
EWD 3 Training Course Part 30: Modularising QEWD Applications
 
EWD 3 Training Course Part 4: Installing & Configuring QEWD
EWD 3 Training Course Part 4: Installing & Configuring QEWDEWD 3 Training Course Part 4: Installing & Configuring QEWD
EWD 3 Training Course Part 4: Installing & Configuring QEWD
 
EWD 3 Training Course Part 35: QEWD Session Locking
EWD 3 Training Course Part 35: QEWD Session LockingEWD 3 Training Course Part 35: QEWD Session Locking
EWD 3 Training Course Part 35: QEWD Session Locking
 
EWD 3 Training Course Part 3: Summary of EWD 3 Modules
EWD 3 Training Course Part 3: Summary of EWD 3 ModulesEWD 3 Training Course Part 3: Summary of EWD 3 Modules
EWD 3 Training Course Part 3: Summary of EWD 3 Modules
 
EWD 3 Training Course Part 16: QEWD Services
EWD 3 Training Course Part 16: QEWD ServicesEWD 3 Training Course Part 16: QEWD Services
EWD 3 Training Course Part 16: QEWD Services
 
EWD 3 Training Course Part 34: QEWD Resilient Mode
EWD 3 Training Course Part 34: QEWD Resilient ModeEWD 3 Training Course Part 34: QEWD Resilient Mode
EWD 3 Training Course Part 34: QEWD Resilient Mode
 
EWD 3 Training Course Part 15: Using a Framework other than jQuery with QEWD
EWD 3 Training Course Part 15: Using a Framework other than jQuery with QEWDEWD 3 Training Course Part 15: Using a Framework other than jQuery with QEWD
EWD 3 Training Course Part 15: Using a Framework other than jQuery with QEWD
 
EWD 3 Training Course Part 27: The QEWD Session
EWD 3 Training Course Part 27: The QEWD SessionEWD 3 Training Course Part 27: The QEWD Session
EWD 3 Training Course Part 27: The QEWD Session
 
EWD 3 Training Course Part 6: What Happens when a QEWD Application is Started
EWD 3 Training Course Part 6: What Happens when a QEWD Application is StartedEWD 3 Training Course Part 6: What Happens when a QEWD Application is Started
EWD 3 Training Course Part 6: What Happens when a QEWD Application is Started
 
EWD 3 Training Course Part 31: Using QEWD for Web and REST Services
EWD 3 Training Course Part 31: Using QEWD for Web and REST ServicesEWD 3 Training Course Part 31: Using QEWD for Web and REST Services
EWD 3 Training Course Part 31: Using QEWD for Web and REST Services
 
EWD 3 Training Course Part 2: EWD 3 Overview
EWD 3 Training Course Part 2: EWD 3 OverviewEWD 3 Training Course Part 2: EWD 3 Overview
EWD 3 Training Course Part 2: EWD 3 Overview
 
EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap...
EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap...EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap...
EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap...
 
EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...
EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...
EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...
 
EWD 3 Training Course Part 7: Applying the QEWD Messaging Pattern
EWD 3 Training Course Part 7: Applying the QEWD Messaging PatternEWD 3 Training Course Part 7: Applying the QEWD Messaging Pattern
EWD 3 Training Course Part 7: Applying the QEWD Messaging Pattern
 
EWD 3 Training Course Part 10: QEWD Sessions and User Authentication
EWD 3 Training Course Part 10: QEWD Sessions and User AuthenticationEWD 3 Training Course Part 10: QEWD Sessions and User Authentication
EWD 3 Training Course Part 10: QEWD Sessions and User Authentication
 
EWD 3 Training Course Part 9: Complex QEWD Messages and Responses
EWD 3 Training Course Part 9: Complex QEWD Messages and ResponsesEWD 3 Training Course Part 9: Complex QEWD Messages and Responses
EWD 3 Training Course Part 9: Complex QEWD Messages and Responses
 
EWD 3 Training Course Part 44: Creating MicroServices with QEWD.js
EWD 3 Training Course Part 44: Creating MicroServices with QEWD.jsEWD 3 Training Course Part 44: Creating MicroServices with QEWD.js
EWD 3 Training Course Part 44: Creating MicroServices with QEWD.js
 
EWD 3 Training Course Part 45: Using QEWD's Advanced MicroService Functionality
EWD 3 Training Course Part 45: Using QEWD's Advanced MicroService FunctionalityEWD 3 Training Course Part 45: Using QEWD's Advanced MicroService Functionality
EWD 3 Training Course Part 45: Using QEWD's Advanced MicroService Functionality
 
ewd-qoper8-vistarpc: Exposing VistA's RPCs as REST Services
ewd-qoper8-vistarpc: Exposing VistA's RPCs as REST Servicesewd-qoper8-vistarpc: Exposing VistA's RPCs as REST Services
ewd-qoper8-vistarpc: Exposing VistA's RPCs as REST Services
 
qewd-ripple: The Ripple OSI Middle Tier
qewd-ripple: The Ripple OSI Middle Tierqewd-ripple: The Ripple OSI Middle Tier
qewd-ripple: The Ripple OSI Middle Tier
 

Destacado

Destacado (11)

EWD 3 Training Course Part 20: The DocumentNode Object
EWD 3 Training Course Part 20: The DocumentNode ObjectEWD 3 Training Course Part 20: The DocumentNode Object
EWD 3 Training Course Part 20: The DocumentNode Object
 
EWD 3 Training Course Part 24: Traversing a Document's Leaf Nodes
EWD 3 Training Course Part 24: Traversing a Document's Leaf NodesEWD 3 Training Course Part 24: Traversing a Document's Leaf Nodes
EWD 3 Training Course Part 24: Traversing a Document's Leaf Nodes
 
EWD 3 Training Course Part 25: Document Database Capabilities
EWD 3 Training Course Part 25: Document Database CapabilitiesEWD 3 Training Course Part 25: Document Database Capabilities
EWD 3 Training Course Part 25: Document Database Capabilities
 
EWD 3 Training Course Part 26: Event-driven Indexing
EWD 3 Training Course Part 26: Event-driven IndexingEWD 3 Training Course Part 26: Event-driven Indexing
EWD 3 Training Course Part 26: Event-driven Indexing
 
EWD 3 Training Course Part 21: Persistent JavaScript Objects
EWD 3 Training Course Part 21: Persistent JavaScript ObjectsEWD 3 Training Course Part 21: Persistent JavaScript Objects
EWD 3 Training Course Part 21: Persistent JavaScript Objects
 
EWD 3 Training Course Part 1: How Node.js Integrates With Global Storage Data...
EWD 3 Training Course Part 1: How Node.js Integrates With Global Storage Data...EWD 3 Training Course Part 1: How Node.js Integrates With Global Storage Data...
EWD 3 Training Course Part 1: How Node.js Integrates With Global Storage Data...
 
EWD 3 Training Course Part 18: Modelling NoSQL Databases using Global Storage
EWD 3 Training Course Part 18: Modelling NoSQL Databases using Global StorageEWD 3 Training Course Part 18: Modelling NoSQL Databases using Global Storage
EWD 3 Training Course Part 18: Modelling NoSQL Databases using Global Storage
 
EWD 3 Training Course Part 13: Putting Everything so far into Practice using ...
EWD 3 Training Course Part 13: Putting Everything so far into Practice using ...EWD 3 Training Course Part 13: Putting Everything so far into Practice using ...
EWD 3 Training Course Part 13: Putting Everything so far into Practice using ...
 
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
 
EWD 3 Training Course Part 17: Introduction to Global Storage Databases
EWD 3 Training Course Part 17: Introduction to Global Storage DatabasesEWD 3 Training Course Part 17: Introduction to Global Storage Databases
EWD 3 Training Course Part 17: Introduction to Global Storage Databases
 
EWD 3 Training Course Part 33: Configuring QEWD to use CORS
EWD 3 Training Course Part 33: Configuring QEWD to use CORSEWD 3 Training Course Part 33: Configuring QEWD to use CORS
EWD 3 Training Course Part 33: Configuring QEWD to use CORS
 

Similar a EWD 3 Training Course Part 19: The cache.node APIs

Parkjihoon phonegap research_for_bada
Parkjihoon phonegap research_for_badaParkjihoon phonegap research_for_bada
Parkjihoon phonegap research_for_bada
웹데브모바일
 

Similar a EWD 3 Training Course Part 19: The cache.node APIs (20)

betterCode Workshop: Effizientes DevOps-Tooling mit Go
betterCode Workshop:  Effizientes DevOps-Tooling mit GobetterCode Workshop:  Effizientes DevOps-Tooling mit Go
betterCode Workshop: Effizientes DevOps-Tooling mit Go
 
Native Hadoop with prebuilt spark
Native Hadoop with prebuilt sparkNative Hadoop with prebuilt spark
Native Hadoop with prebuilt spark
 
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
 
Challenges of container configuration
Challenges of container configurationChallenges of container configuration
Challenges of container configuration
 
Kubernetes security
Kubernetes securityKubernetes security
Kubernetes security
 
EWD 3 Training Course Part 22: Traversing Documents using DocumentNode Objects
EWD 3 Training Course Part 22: Traversing Documents using DocumentNode ObjectsEWD 3 Training Course Part 22: Traversing Documents using DocumentNode Objects
EWD 3 Training Course Part 22: Traversing Documents using DocumentNode Objects
 
Excelian hyperledger walkthrough-feb17
Excelian hyperledger walkthrough-feb17Excelian hyperledger walkthrough-feb17
Excelian hyperledger walkthrough-feb17
 
Monitoring CloudStack and components
Monitoring CloudStack and componentsMonitoring CloudStack and components
Monitoring CloudStack and components
 
Nomad, l'orchestration made in Hashicorp - Bastien Cadiot
Nomad, l'orchestration made in Hashicorp - Bastien CadiotNomad, l'orchestration made in Hashicorp - Bastien Cadiot
Nomad, l'orchestration made in Hashicorp - Bastien Cadiot
 
Deploying Cloud Native Red Team Infrastructure with Kubernetes, Istio and Envoy
Deploying Cloud Native Red Team Infrastructure with Kubernetes, Istio and Envoy Deploying Cloud Native Red Team Infrastructure with Kubernetes, Istio and Envoy
Deploying Cloud Native Red Team Infrastructure with Kubernetes, Istio and Envoy
 
New and cool in OSGi R7 - David Bosschaert & Carsten Ziegeler
New and cool in OSGi R7 - David Bosschaert & Carsten ZiegelerNew and cool in OSGi R7 - David Bosschaert & Carsten Ziegeler
New and cool in OSGi R7 - David Bosschaert & Carsten Ziegeler
 
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
 
Postgres the hardway
Postgres the hardwayPostgres the hardway
Postgres the hardway
 
Gradle: The Build System you have been waiting for!
Gradle: The Build System you have been waiting for!Gradle: The Build System you have been waiting for!
Gradle: The Build System you have been waiting for!
 
Parkjihoon phonegap research_for_bada
Parkjihoon phonegap research_for_badaParkjihoon phonegap research_for_bada
Parkjihoon phonegap research_for_bada
 
Drone CI/CD 自動化測試及部署
Drone CI/CD 自動化測試及部署Drone CI/CD 自動化測試及部署
Drone CI/CD 自動化測試及部署
 
BeJUG Meetup - What's coming in the OSGi R7 Specification
BeJUG Meetup - What's coming in the OSGi R7 SpecificationBeJUG Meetup - What's coming in the OSGi R7 Specification
BeJUG Meetup - What's coming in the OSGi R7 Specification
 
Jörg Schad - Hybrid Cloud (Kubernetes, Spark, HDFS, …)-as-a-Service - Codemot...
Jörg Schad - Hybrid Cloud (Kubernetes, Spark, HDFS, …)-as-a-Service - Codemot...Jörg Schad - Hybrid Cloud (Kubernetes, Spark, HDFS, …)-as-a-Service - Codemot...
Jörg Schad - Hybrid Cloud (Kubernetes, Spark, HDFS, …)-as-a-Service - Codemot...
 
Jörg Schad - Hybrid Cloud (Kubernetes, Spark, HDFS, …)-as-a-Service - Codemot...
Jörg Schad - Hybrid Cloud (Kubernetes, Spark, HDFS, …)-as-a-Service - Codemot...Jörg Schad - Hybrid Cloud (Kubernetes, Spark, HDFS, …)-as-a-Service - Codemot...
Jörg Schad - Hybrid Cloud (Kubernetes, Spark, HDFS, …)-as-a-Service - Codemot...
 
Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境
Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境
Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境
 

Más de Rob Tweed

Más de Rob Tweed (10)

QEWD Update
QEWD UpdateQEWD Update
QEWD Update
 
Data Persistence as a Language Feature
Data Persistence as a Language FeatureData Persistence as a Language Feature
Data Persistence as a Language Feature
 
LNUG: Having Your Node.js Cake and Eating It Too
LNUG: Having Your Node.js Cake and Eating It TooLNUG: Having Your Node.js Cake and Eating It Too
LNUG: Having Your Node.js Cake and Eating It Too
 
EWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST Services
EWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST ServicesEWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST Services
EWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST Services
 
QEWD.js, JSON Web Tokens & MicroServices
QEWD.js, JSON Web Tokens & MicroServicesQEWD.js, JSON Web Tokens & MicroServices
QEWD.js, JSON Web Tokens & MicroServices
 
QEWD.js: Have your Node.js Cake and Eat It Too
QEWD.js: Have your Node.js Cake and Eat It TooQEWD.js: Have your Node.js Cake and Eat It Too
QEWD.js: Have your Node.js Cake and Eat It Too
 
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
 
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
 
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 2
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 2EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 2
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 2
 
EWD 3 Training Course Part 32: Configuring QEWD to use SSL/HTTPS
EWD 3 Training Course Part 32: Configuring QEWD to use SSL/HTTPSEWD 3 Training Course Part 32: Configuring QEWD to use SSL/HTTPS
EWD 3 Training Course Part 32: Configuring QEWD to use SSL/HTTPS
 

Último

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Último (20)

%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 

EWD 3 Training Course Part 19: The cache.node APIs

  • 1. Copyright © 2016 M/Gateway Developments Ltd EWD 3 Training Course Part 19 Accessing a Global Storage Database from JavaScript: the cache.node APIs Rob Tweed Director, M/Gateway Developments Ltd Twitter: @rtweed
  • 2. Copyright © 2016 M/Gateway Developments Ltd cache.node • The cache.node interface module allows you to access a Caché database from JavaScript
  • 3. Copyright © 2016 M/Gateway Developments Ltd NodeM • The NodeM module is an Open Source emulation of cache.node, allowing the GT.M database to be accessed identically from JavaScript – https://github.com/dlwicksell/nodem
  • 4. Copyright © 2016 M/Gateway Developments Ltd ewd-redis-globals • The Redis-based ewd-redis-globals implementation of Global Storage includes an implementation of the cache.node APIs, allowing the database to be accessed identically from JavaScript – https://github.com/robtweed/ewd-redis-globals
  • 5. Copyright © 2016 M/Gateway Developments Ltd cache.node, NodeM & ewd-redis-globals APIs When accessed in a QEWD application: this.db.{{someFunctioName}}()
  • 6. Copyright © 2016 M/Gateway Developments Ltd Loading and Initialising the Interface Modules These steps are done for you automatically by QEWD Here’s how to do it manually, eg if you're creating a standalone test-harness…
  • 7. Copyright © 2016 M/Gateway Developments Ltd cache.node APIs Loading cache.node: var interface = require('cache'); var db = new interface.Cache();
  • 8. Copyright © 2016 M/Gateway Developments Ltd cache.node APIs Opening connection to Caché : db.open({ path: '/opt/cache/mgr', username: '_SYSTEM', password: 'SYS', namespace: 'USER', charset: 'UTF-8', lock: 0 });
  • 9. Copyright © 2016 M/Gateway Developments Ltd cache.node APIs Closing connection to Caché: var ok = db.close();
  • 10. Copyright © 2016 M/Gateway Developments Ltd NodeM (GT.M) APIs Loading NodeM: var interface = require('nodem'); var db = new interface.Gtm();
  • 11. Copyright © 2016 M/Gateway Developments Ltd NodeM APIs Opening connection to GT.M: db.open();
  • 12. Copyright © 2016 M/Gateway Developments Ltd NodeM APIs Opening connection to GT.M: db.open(); Thereafter, all APIs are identical to those used with cache.node
  • 13. Copyright © 2016 M/Gateway Developments Ltd NodeM APIs Closing connection to GT.M: var ok = db.close(); ie: Identical to cache.node
  • 14. Copyright © 2016 M/Gateway Developments Ltd ewd-redis-globals APIs Loading ewd-redis-globals: var interface = require('ewd-redis-globals'); var db = new interface();
  • 15. Copyright © 2016 M/Gateway Developments Ltd Opening connection to Redis / ewd-redis-globals: db.open(); ewd-redis-globals APIs
  • 16. Copyright © 2016 M/Gateway Developments Ltd Thereafter, all APIs are identical to those used with cache.node Opening connection to Redis / ewd-redis-globals: db.open(); ewd-redis-globals APIs
  • 17. Copyright © 2016 M/Gateway Developments Ltd Closing connection to Redis / ewd-redis-globals: var ok = db.close(); ie: Identical to cache.node ewd-redis-globals APIs
  • 18. Copyright © 2016 M/Gateway Developments Ltd Setting up a test harness • Ready to use example for Caché in QEWD: – C:qewdnode_modulesqewdexampletest.js – Needs editing to match your Caché (or other database) configuration • Use previous slides for GT.M and Redis
  • 19. Copyright © 2016 M/Gateway Developments Ltd Edit test.js var interface = require('cache'); var db = new interface.Cache(); console.log('db: ' + JSON.stringify(db)); // Change these parameters to match your GlobalsDB or Cache system: var ok = db.open({ path: '/opt/cache/mgr', username: '_SYSTEM', password: 'SYS', namespace: 'USER' }); console.log('ok: ' + JSON.stringify(ok)); console.log(db.version()); var node = { global: 'rob', subscripts: [1], data: 'hello' }; db.set(node); var result = db.get(node); console.log(JSON.stringify(result)); db.close();
  • 20. Copyright © 2016 M/Gateway Developments Ltd Edit test.js var interface = require('cache'); var db = new interface.Cache(); console.log('db: ' + JSON.stringify(db)); // Change these parameters to match your GlobalsDB or Cache system: var ok = db.open({ path: 'C:InterSystemsCache2015-2mgr', username: '_SYSTEM', password: 'SYS', namespace: 'USER' }); console.log('ok: ' + JSON.stringify(ok)); console.log(db.version()); var node = { global: 'rob', subscripts: [1], data: 'hello' }; db.set(node); var result = db.get(node); console.log(JSON.stringify(result)); db.close();
  • 21. Copyright © 2016 M/Gateway Developments Ltd Save as C:qewdtest.js var interface = require('cache'); var db = new interface.Cache(); console.log('db: ' + JSON.stringify(db)); // Change these parameters to match your GlobalsDB or Cache system: var ok = db.open({ path: 'C:InterSystemsCache2015-2mgr', username: '_SYSTEM', password: 'SYS', namespace: 'USER' }); console.log('ok: ' + JSON.stringify(ok)); console.log(db.version()); var node = { global: 'rob', subscripts: [1], data: 'hello' }; db.set(node); var result = db.get(node); console.log(JSON.stringify(result)); db.close();
  • 22. Copyright © 2016 M/Gateway Developments Ltd Run it cd qewd (or on Linux / Raspberry Pi: cd /qewd ) node test
  • 23. Copyright © 2016 M/Gateway Developments Ltd Run it cd qewd node test db: {} ok: {"ok":1,"result":1,"cache_pid":2960} Node.js Adaptor for Cache: Version: 1.1.113 (CM); Cache Version: 2015.2 build 66 4 {"global":"rob","subscripts":[1],"data":"hello","ok":1,"defined":1}
  • 24. Copyright © 2016 M/Gateway Developments Ltd One difference between test harness and QEWD • Test harness: invoke cache.node APIs using: – db.xxx() • In QEWD worker module, they are accessed using: – this.db.xxx()
  • 25. Copyright © 2016 M/Gateway Developments Ltd One difference between test harness and QEWD • Test harness: invoke cache.node APIs using: – db.xxx() db.set(node); var result = db.get(node); console.log(JSON.stringify(result)); db.close();
  • 26. Copyright © 2016 M/Gateway Developments Ltd One difference between test harness and QEWD • In QEWD worker module: – this.db.xxx() • Note: QEWD opens the database automatically when a worker is started, and closes it automatically when the worker is stopped this.db.set(node); var result = this.db.get(node); console.log(JSON.stringify(result));
  • 27. Copyright © 2016 M/Gateway Developments Ltd The Basic Global Storage APIs
  • 28. Copyright © 2016 M/Gateway Developments Ltd Global Storage handling APIs Accessing global nodes: - set - get - delete (kill)
  • 29. Copyright © 2016 M/Gateway Developments Ltd Defining a Global Node: var node = { global: 'employee', subscripts: [123456, 'name'] }; Global Storage handling APIs
  • 30. Copyright © 2016 M/Gateway Developments Ltd Defining a Global Node: var node = { global: 'employee', subscripts: [123456, 'name'] }; employee(123456,"name") Global Storage handling APIs
  • 31. Copyright © 2016 M/Gateway Developments Ltd Accessing global nodes: - set node.data = 'Rob Tweed'; this.db.set(node); Global Storage handling APIs
  • 32. Copyright © 2016 M/Gateway Developments Ltd Accessing global nodes: - get var value = this.db.get(node).data; Global Storage handling APIs
  • 33. Copyright © 2016 M/Gateway Developments Ltd Accessing global nodes: - kill this.db.kill(node); Global Storage handling APIs
  • 34. Copyright © 2016 M/Gateway Developments Ltd Traversing Global Subscripts
  • 35. Copyright © 2016 M/Gateway Developments Ltd Traversing global nodes: - Iterate through subscripts Global Storage handling APIs
  • 36. Copyright © 2016 M/Gateway Developments Ltd Traversing global nodes: - Iterate through subscripts at a particular hierarchy level myGlobal("a")=123 myGlobal("b","c1")="foo" myGlobal("b","c2")="foo2" myGlobal("d","e1","f1")="bar1" myGlobal("d","e1","f2")="bar2" myGlobal("d","e2","f1")="bar1" myGlobal("d","e2","f2")="bar2" myGlobal("d","e2","f3")="bar3" myGlobal "a" 123 "b" "c2" "foo2" "d" "c1" "foo" "e2" "e1" "f2" "bar2" "f1" "bar1" "f2" "bar2" "f1" "bar1" "f3" "bar3" "a", "b", "d" Global Storage handling APIs
  • 37. Copyright © 2016 M/Gateway Developments Ltd Traversing global nodes: - Iterate through subscripts at a particular hierarchy level myGlobal("a")=123 myGlobal("b","c1")="foo" myGlobal("b","c2")="foo2" myGlobal("d","e1","f1")="bar1" myGlobal("d","e1","f2")="bar2" myGlobal("d","e2","f1")="bar1" myGlobal("d","e2","f2")="bar2" myGlobal("d","e2","f3")="bar3" myGlobal "a" 123 "b" "c2" "foo2" "d" "c1" "foo" "e2" "e1" "f2" "bar2" "f1" "bar1" "f2" "bar2" "f1" "bar1" "f3" "bar3" "e1", "e2" Global Storage handling APIs
  • 38. Copyright © 2016 M/Gateway Developments Ltd Traversing global nodes: - Iterate through subscripts at a particular hierarchy level myGlobal("a")=123 myGlobal("b","c1")="foo" myGlobal("b","c2")="foo2" myGlobal("d","e1","f1")="bar1" myGlobal("d","e1","f2")="bar2" myGlobal("d","e2","f1")="bar1" myGlobal("d","e2","f2")="bar2" myGlobal("d","e2","f3")="bar3" myGlobal "a" 123 "b" "c2" "foo2" "d" "c1" "foo" "e2" "e1" "f2" "bar2" "f1" "bar1" "f2" "bar2" "f1" "bar1" "f3" "bar3" "f1", "f2", "f3" Global Storage handling APIs
  • 39. Copyright © 2016 M/Gateway Developments Ltd myGlobal("d","e2","f1")="bar1" myGlobal("d","e2","f2")="bar2" myGlobal("d","e2","f3")="bar3" "f1", "f2", "f3" Global Storage handling APIs To achieve the following traversal:
  • 40. Copyright © 2016 M/Gateway Developments Ltd Traversing Global Node: var node = { global: 'myGlobal', subscripts: ['d', 'e2', '' ] }; myGlobal("d","e2","f1")="bar1" myGlobal("d","e2","f2")="bar2" myGlobal("d","e2","f3")="bar3" "f1", "f2", "f3" Global Storage handling APIs
  • 41. Copyright © 2016 M/Gateway Developments Ltd Traversing Global Node: var node = { global: 'myGlobal', subscripts: ['d', 'e2', '' ] }; myGlobal("d","e2","f1")="bar1" myGlobal("d","e2","f2")="bar2" myGlobal("d","e2","f3")="bar3" "f1", "f2", "f3" "seed" value to start iterator Empty string Global Storage handling APIs
  • 42. Copyright © 2016 M/Gateway Developments Ltd Traversing Global Node: var node = { global: 'myGlobal', subscripts: ['d', 'e2', '' ] }; var subscript = this.db.order(node).result; // 'f1' myGlobal("d","e2","f1")="bar1" myGlobal("d","e2","f2")="bar2" myGlobal("d","e2","f3")="bar3" "f1", "f2", "f3" Global Storage handling APIs
  • 43. Copyright © 2016 M/Gateway Developments Ltd Traversing Global Node: var node = { global: 'myGlobal', subscripts: ['d', 'e2', '' ] }; var subscript = this.db.order(node).result; // 'f1' subscript = this.db.order(node).result; // 'f2' myGlobal("d","e2","f1")="bar1" myGlobal("d","e2","f2")="bar2" myGlobal("d","e2","f3")="bar3" "f1", "f2", "f3" Global Storage handling APIs
  • 44. Copyright © 2016 M/Gateway Developments Ltd Traversing Global Node: var node = { global: 'myGlobal', subscripts: ['d', 'e2', '' ] }; var subscript = this.db.order(node).result; // 'f1' subscript = this.db.order(node).result; // 'f2' subscript = this.db.order(node).result; // 'f3' myGlobal("d","e2","f1")="bar1" myGlobal("d","e2","f2")="bar2" myGlobal("d","e2","f3")="bar3" "f1", "f2", "f3" Global Storage handling APIs
  • 45. Copyright © 2016 M/Gateway Developments Ltd Traversing Global Node: var node = { global: 'myGlobal', subscripts: ['d', 'e2', '' ] }; var subscript = this.db.order(node).result; // 'f1' subscript = this.db.order(node).result; // 'f2' subscript = this.db.order(node).result; // 'f3' subscript = this.db.order(node).result; // '' myGlobal("d","e2","f1")="bar1" myGlobal("d","e2","f2")="bar2" myGlobal("d","e2","f3")="bar3" "f1", "f2", "f3" Global Storage handling APIs
  • 46. Copyright © 2016 M/Gateway Developments Ltd Traversing Global Node: var node = { global: 'myGlobal', subscripts: ['d', 'e2', 'f2' ] }; var subscript = this.db.order(node).result; // 'f3' myGlobal("d","e2","f1")="bar1" myGlobal("d","e2","f2")="bar2" myGlobal("d","e2","f3")="bar3" "f3" "seed" value to start iterator Start from f2 Global Storage handling APIs
  • 47. Copyright © 2016 M/Gateway Developments Ltd Traversing Global Node: var subscript = this.db.order(node).result; // 'f3' node is now: { global: 'myGlobal', subscripts: ['d', 'e2', 'f3' ] }; myGlobal("d","e2","f1")="bar1" myGlobal("d","e2","f2")="bar2" myGlobal("d","e2","f3")="bar3" Global Storage handling APIs
  • 48. Copyright © 2016 M/Gateway Developments Ltd Traversing Global Node: var node = { global: 'myGlobal', subscripts: ['d', 'e2', 'f2' ] }; var subscript = this.db.order(node).result; // 'f3' subscript = this.db.order(node).result; // '' myGlobal("d","e2","f1")="bar1" myGlobal("d","e2","f2")="bar2" myGlobal("d","e2","f3")="bar3" "" Global Storage handling APIs Empty string means no further subscripts, so traversal is complete
  • 49. Copyright © 2016 M/Gateway Developments Ltd Traversing Global Node – generic loop: var node = { global: 'myGlobal', subscripts: ['d', 'e2', '' ] }; var subscript; do { subscript = this.db.order(node).result; if (subscript !== '') console.log(subscript); } while (subscript !== ''); myGlobal("d","e2","f1")="bar1" myGlobal("d","e2","f2")="bar2" myGlobal("d","e2","f3")="bar3" "f1", "f2", "f3" Global Storage handling APIs
  • 50. Copyright © 2016 M/Gateway Developments Ltd The APIs are low-level • Deliberately designed to provide the basic means of access to Global Storage and nothing more • They assume you understand the mechanics of Global Storage • Too low-level for JavaScript development – Traversal, in particular, requires a lot of code • However, they can be abstracted to a more JavaScript-centric point of view – Which is the subject of the next part of this course