1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | 'use strict';
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | require('dotenv').config();
|
38 |
|
39 | var DocumentStore = require('ewd-document-store');
|
40 | var Cache = require('cache').Cache;
|
41 | var db = new Cache();
|
42 |
|
43 |
|
44 | var ok = db.open({
|
45 | path: process.env.CACHE_MGR_PATH || '/opt/cache/mgr',
|
46 | username: process.env.CACHE_USERNAME || '_SYSTEM',
|
47 | password: process.env.CACHE_PASSWORD || 'SYS',
|
48 | namespace: process.env.CACHE_NAMESPACE || 'USER'
|
49 | });
|
50 |
|
51 | console.log('ok: ' + JSON.stringify(ok));
|
52 | console.log('version: ' + db.version());
|
53 |
|
54 | var documentStore = new DocumentStore(db);
|
55 | var rob = new documentStore.DocumentNode('rob');
|
56 |
|
57 | var temp = new documentStore.DocumentNode('temp', [1]);
|
58 | console.log('exists: ' + temp.exists);
|
59 | console.log('hasValue: ' + temp.hasValue);
|
60 | console.log('hasChildren: ' + temp.hasChildren);
|
61 | console.log('value: ' + temp.value);
|
62 |
|
63 | console.log(JSON.stringify(temp.getDocument(), null, 2));
|
64 |
|
65 | documentStore.on('afterSet', function (node) {
|
66 | console.log('afterSet: ' + JSON.stringify(node));
|
67 | });
|
68 |
|
69 | rob.$('x').value = 'hello';
|
70 | rob.$('y').value = 'world';
|
71 | rob.$('a').increment();
|
72 |
|
73 | var z = {
|
74 | a: 'this is a',
|
75 | b: 'this is b',
|
76 | Barton: 'J',
|
77 | Briggs: 'A',
|
78 | Davies: 'D',
|
79 | Davis: 'T',
|
80 | Douglas: 'N',
|
81 | c: ['a', 's', 'd'],
|
82 | d: {
|
83 | a: 'a',
|
84 | b: 'b'
|
85 | }
|
86 | };
|
87 |
|
88 | rob.$('z').setDocument(z);
|
89 |
|
90 | console.log(JSON.stringify(rob.getDocument(), null, 2));
|
91 |
|
92 | console.log('forEachChild through rob document:');
|
93 | rob.forEachChild(function (nodeName) {
|
94 | console.log(nodeName);
|
95 | });
|
96 |
|
97 | console.log('forEachChild through rob document, stopping early:');
|
98 | rob.forEachChild(function (nodeName) {
|
99 | console.log(nodeName);
|
100 | if (nodeName === 'x') {
|
101 | return true;
|
102 | }
|
103 | });
|
104 |
|
105 | console.log('forEachChild through rob document, in reverse:');
|
106 | rob.forEachChild({
|
107 | direction: 'reverse'
|
108 | }, function (nodeName) {
|
109 | console.log(nodeName);
|
110 | });
|
111 |
|
112 | console.log('forPrefix through rob global starting x:');
|
113 | rob.forEachChild({
|
114 | prefix: 'x'
|
115 | }, function (subscript) {
|
116 | console.log(subscript);
|
117 | });
|
118 |
|
119 | console.log('forEachLeafNode through rob global:');
|
120 | rob.forEachLeafNode(function (value) {
|
121 | console.log(value);
|
122 | });
|
123 |
|
124 | console.log('Number of children: ' + rob.countChildren());
|
125 |
|
126 | var robx = rob.$('x', true);
|
127 | console.log('robx: ' + robx.value);
|
128 | console.log(JSON.stringify(rob, null, 2));
|
129 | console.log('===============');
|
130 | console.log(JSON.stringify(robx, null, 2));
|
131 |
|
132 | var roby = rob.$x.$('y');
|
133 | console.log('parent: ' + roby.parent.value);
|
134 |
|
135 | var first = rob.firstChild;
|
136 | console.log('first: ' + first.name);
|
137 | console.log('next = ' + first.nextSibling.name);
|
138 |
|
139 | var last = rob.lastChild;
|
140 | console.log('last: ' + last.name);
|
141 | console.log('previous = ' + last.previousSibling.name);
|
142 |
|
143 | var z = rob.$z;
|
144 | console.log('Names from Br to Da');
|
145 | z.forEachChild({
|
146 | range: {
|
147 | from: 'Br',
|
148 | to: 'Da'
|
149 | }
|
150 | }, function (lastName, node) {
|
151 | console.log('LastName: ' + lastName + '; firstName: ' + node.value);
|
152 | });
|
153 | console.log('------------');
|
154 | console.log('Names from Br to Db');
|
155 | z.forEachChild({
|
156 | range: {
|
157 | from: 'Br',
|
158 | to: 'Db'
|
159 | }
|
160 | }, function (lastName, node) {
|
161 | console.log('LastName: ' + lastName + '; firstName: ' + node.value);
|
162 | });
|
163 | console.log('------------');
|
164 | console.log('Names from Briggs to Davis');
|
165 | z.forEachChild({
|
166 | range: {
|
167 | from: 'Briggs',
|
168 | to: 'Davis'
|
169 | }
|
170 | }, function (lastName, node) {
|
171 | console.log('LastName: ' + lastName + '; firstName: ' + node.value);
|
172 | });
|
173 | console.log('------------');
|
174 | console.log('Names from B to D');
|
175 | z.forEachChild({
|
176 | range: {
|
177 | from: 'B',
|
178 | to: 'D'
|
179 | }
|
180 | }, function (lastName, node) {
|
181 | console.log('LastName: ' + lastName + '; firstName: ' + node.value);
|
182 | });
|
183 | console.log('------------');
|
184 | console.log('Names from B');
|
185 | z.forEachChild({
|
186 | range: {
|
187 | from: 'B'
|
188 | }
|
189 | }, function (lastName, node) {
|
190 |
|
191 | console.log('LastName: ' + lastName);
|
192 | });
|
193 | console.log('------------');
|
194 | console.log('Names from D');
|
195 | z.forEachChild({
|
196 | range: {
|
197 | from: 'D'
|
198 | }
|
199 | }, function (lastName, node) {
|
200 |
|
201 | console.log('LastName: ' + lastName);
|
202 | });
|
203 | console.log('------------');
|
204 | console.log('Names to D');
|
205 | z.forEachChild({
|
206 | range: {
|
207 | to: 'D'
|
208 | }
|
209 | }, function (lastName, node) {
|
210 |
|
211 | console.log('LastName: ' + lastName);
|
212 | });
|
213 | console.log('------------');
|
214 |
|
215 | console.log('temp before: ' + temp.value);
|
216 | temp.value = 1234;
|
217 | console.log('temp after: ' + temp.value);
|
218 |
|
219 | temp.delete();
|
220 | console.log('temp after delete: ' + temp.value);
|
221 |
|
222 | var list = documentStore.list();
|
223 | console.log(JSON.stringify(list));
|
224 |
|
225 | db.close();
|