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