1
1
import Long from 'long'
2
2
import {
3
- Client ,
4
- verifyVerification ,
5
- types ,
6
- stream ,
3
+ Client ,
4
+ verifyVerification ,
5
+ types ,
6
+ stream ,
7
7
} from '@codenotary/immudb-node'
8
8
9
9
10
10
11
11
12
12
13
13
overviewSchowcase ( )
14
- . catch ( console . error )
14
+ . catch ( console . error )
15
15
16
16
17
17
async function overviewSchowcase ( ) {
18
18
19
-
19
+
20
20
const client = new Client ( {
21
- host : '127.0.0.1' ,
22
- port : 3322 ,
23
- user : 'immudb' ,
24
- password : 'immudb' ,
25
- database : 'defaultdb' ,
21
+ host : '127.0.0.1' ,
22
+ port : 3322 ,
23
+ user : 'immudb' ,
24
+ password : 'immudb' ,
25
+ database : 'defaultdb' ,
26
26
} )
27
27
28
28
@@ -35,8 +35,8 @@ async function overviewSchowcase() {
35
35
36
36
const valEntries2 = await client . setValEntries ( {
37
37
kvms : [
38
- { key : Buffer . of ( 0 ) , val : Buffer . of ( 0 ) } ,
39
- { key : Buffer . of ( 1 ) , val : Buffer . of ( 1 ) } ,
38
+ { key : Buffer . of ( 0 ) , val : Buffer . of ( 0 ) } ,
39
+ { key : Buffer . of ( 1 ) , val : Buffer . of ( 1 ) } ,
40
40
]
41
41
} )
42
42
console . log ( 'valEntries2:' )
@@ -45,47 +45,47 @@ async function overviewSchowcase() {
45
45
46
46
const valEntry3 = await client . setValEntries ( {
47
47
kvms : [
48
- { key : Buffer . of ( 2 ) , val : Buffer . of ( 2 ) } ,
48
+ { key : Buffer . of ( 2 ) , val : Buffer . of ( 2 ) } ,
49
49
]
50
50
} )
51
51
console . log ( 'valEntry3:' )
52
52
console . log ( valEntry3 )
53
53
54
54
55
55
const refEntry4 = await client . setRefEntry ( {
56
- key : Buffer . of ( 3 ) ,
56
+ key : Buffer . of ( 3 ) ,
57
57
referToKey : valEntries2 . valEntries [ 0 ] . key ,
58
- keyTxId : valEntries2 . valEntries [ 0 ] . id ,
59
- boundRef : true ,
58
+ keyTxId : valEntries2 . valEntries [ 0 ] . id ,
59
+ boundRef : true ,
60
60
} )
61
61
console . log ( 'refEntry4:' )
62
62
console . log ( refEntry4 )
63
63
64
64
65
65
const zSetEntry5 = await client . setZSetEntry ( {
66
- zSet : Buffer . of ( 4 ) ,
67
- referredKey : valEntry3 . valEntries [ 0 ] . key ,
68
- referredKeyScore : 3 ,
66
+ zSet : Buffer . of ( 4 ) ,
67
+ referredKey : valEntry3 . valEntries [ 0 ] . key ,
68
+ referredKeyScore : 3 ,
69
69
} )
70
70
console . log ( 'zSetEntry5:' )
71
71
console . log ( zSetEntry5 )
72
72
73
73
const entries6 = await client . setValRefZSetEntries ( {
74
74
ops : [
75
75
{
76
- type : 'val' ,
77
- key : Buffer . of ( 2 ) ,
78
- val : Buffer . of ( 6 ) ,
76
+ type : 'val' ,
77
+ key : Buffer . of ( 2 ) ,
78
+ val : Buffer . of ( 6 ) ,
79
79
} ,
80
80
{
81
- type : 'ref' ,
82
- key : Buffer . of ( 3 ) ,
81
+ type : 'ref' ,
82
+ key : Buffer . of ( 3 ) ,
83
83
referToKey : valEntry3 . valEntries [ 0 ] . key
84
84
} ,
85
85
{
86
- type : 'zSet' ,
86
+ type : 'zSet' ,
87
87
referredKey : valEntries2 . valEntries [ 1 ] . key ,
88
- zSet : zSetEntry5 . zSetTxEntry . zSet ,
88
+ zSet : zSetEntry5 . zSetTxEntry . zSet ,
89
89
referredKeyScore : 9 ,
90
90
}
91
91
]
@@ -126,7 +126,8 @@ async function overviewSchowcase() {
126
126
console . log ( stream . toKVEntries ( Buffer . concat ( buffs ) ) )
127
127
128
128
129
- const sqlExecCreateTable7 = await client . sqlExec ( { sql : `
129
+ const sqlExecCreateTable7 = await client . sqlExec ( {
130
+ sql : `
130
131
create table if not exists testtable (
131
132
id1 integer not null,
132
133
id2 varchar[3] null,
@@ -140,7 +141,8 @@ async function overviewSchowcase() {
140
141
console . log ( sqlExecCreateTable7 )
141
142
142
143
143
- const sqlExecUpsert8 = await client . sqlExec ( { sql : `
144
+ const sqlExecUpsert8 = await client . sqlExec ( {
145
+ sql : `
144
146
upsert into testtable
145
147
(id1, id2, created, data, isactive)
146
148
values
@@ -153,15 +155,18 @@ async function overviewSchowcase() {
153
155
154
156
155
157
const sqlTxAt8 = await client . executeSqlTx ( 'ReadWrite' , async ( txApi ) => {
156
- const sqlQueryInTxAt8 = await txApi . query ( { sql : `
158
+ const sqlQueryInTxAt8 = await txApi . query ( {
159
+ sql : `
157
160
select * from testtable;
158
161
` } )
159
162
console . log ( 'sqlQueryInTxAt8' )
160
- console . log ( sqlQueryInTxAt8 )
161
-
163
+ for await ( const row of sqlQueryInTxAt8 ) {
164
+ console . log ( row )
165
+ }
162
166
163
167
// sqlExecUpsert9
164
- const sqlExecUpsertInTx9 = txApi . exec ( { sql :`
168
+ const sqlExecUpsertInTx9 = txApi . exec ( {
169
+ sql : `
165
170
upsert into testtable
166
171
(id1, id2, created, data, isactive)
167
172
values
@@ -170,11 +175,14 @@ async function overviewSchowcase() {
170
175
` } )
171
176
172
177
173
- const sqlQueryInTxAt9 = await txApi . query ( { sql : `
178
+ const sqlQueryInTxAt9 = await txApi . query ( {
179
+ sql : `
174
180
select * from testtable;
175
181
` } )
176
182
console . log ( 'sqlQueryInTxAt9' )
177
- console . log ( sqlQueryInTxAt9 )
183
+ for await ( const row of sqlQueryInTxAt9 ) {
184
+ console . log ( row )
185
+ }
178
186
179
187
180
188
throw 'I would like to cancel'
@@ -184,18 +192,19 @@ async function overviewSchowcase() {
184
192
console . log ( sqlTxAt8 )
185
193
186
194
187
- const sqlQueryAt8 = await client . sqlQuery ( { sql : `
195
+ const sqlQueryAt8 = await client . sqlQuery ( {
196
+ sql : `
188
197
select * from testtable;
189
198
` } )
190
199
console . log ( 'sqlQueryInTxAt8' )
191
200
console . log ( sqlQueryAt8 )
192
- const k = sqlQueryAt8 [ 0 ]
193
- const d = k [ 0 ]
194
-
195
-
201
+
202
+ const row = await sqlQueryAt8 . next ( )
203
+ console . log ( row )
204
+
196
205
197
206
const dbScanAt8 = await client . scanDbEntries ( {
198
- scanStartAtTxId : Long . fromValue ( 1 , true ) ,
207
+ scanStartAtTxId : Long . fromValue ( 1 , true ) ,
199
208
} )
200
209
console . log ( 'dbScanAt8' )
201
210
console . log ( dbScanAt8 )
@@ -208,12 +217,12 @@ async function overviewSchowcase() {
208
217
209
218
210
219
const setAndProof9 = await client . setValEntriesGetVerification ( {
211
- kvms : [ { key : Buffer . from ( 'yo' ) , val : Buffer . from ( 'man' ) } ] ,
220
+ kvms : [ { key : Buffer . from ( 'yo' ) , val : Buffer . from ( 'man' ) } ] ,
212
221
refTxId : stateAt8 . txId ,
213
222
refHash : stateAt8 . txHash ,
214
223
} )
215
224
console . log ( 'setAndProof9' )
216
- console . dir ( setAndProof9 , { depth : 10 } )
225
+ console . dir ( setAndProof9 , { depth : 10 } )
217
226
218
227
console . log ( 'verifyVerification(setAndProof9) result:' )
219
228
console . log ( verifyVerification ( setAndProof9 . verification ) )
@@ -232,7 +241,7 @@ async function overviewSchowcase() {
232
241
refTxId : stateAt9 . txId ,
233
242
} )
234
243
console . log ( 'getTx2AndVerification' )
235
- console . log ( getTx2AndVerification , { depth : 10 } )
244
+ console . log ( getTx2AndVerification , { depth : 10 } )
236
245
console . log ( 'verifyVerification(getTx2AndVerification) result:' )
237
246
console . log ( verifyVerification ( getTx2AndVerification . verification ) )
238
247
@@ -241,40 +250,40 @@ async function overviewSchowcase() {
241
250
242
251
// entries6
243
252
const getTx6AndVerification = await client . getTxAndVerification ( {
244
- txId : entries6 . tx . id ,
253
+ txId : entries6 . tx . id ,
245
254
refHash : stateAt9 . txHash ,
246
255
refTxId : stateAt9 . txId ,
247
256
} )
248
257
console . log ( 'getTx6AndVerification' )
249
- console . log ( getTx6AndVerification , { depth : 10 } )
258
+ console . log ( getTx6AndVerification , { depth : 10 } )
250
259
console . log ( 'verifyVerification(getTx6AndVerification) result:' )
251
260
console . log ( verifyVerification ( getTx6AndVerification . verification ) )
252
261
253
262
254
263
255
264
// sqlExecCreateTable7.subTxes[0].tx?.id
256
265
const getTx7AndVerification = await client . getTxAndVerification ( {
257
- txId : Long . fromInt ( 7 , true ) ,
266
+ txId : Long . fromInt ( 7 , true ) ,
258
267
refHash : stateAt9 . txHash ,
259
268
refTxId : stateAt9 . txId ,
260
269
} )
261
270
console . log ( 'getTx7AndVerification' )
262
- console . log ( getTx7AndVerification , { depth : 10 } )
271
+ console . log ( getTx7AndVerification , { depth : 10 } )
263
272
console . log ( 'verifyVerification(getTx7AndVerification) result:' )
264
273
console . log ( verifyVerification ( getTx7AndVerification . verification ) )
265
274
266
275
267
276
// sqlExecUpsert8
268
277
const getTx8AndVerification = await client . getTxAndVerification ( {
269
- txId : Long . fromInt ( 8 , true ) ,
278
+ txId : Long . fromInt ( 8 , true ) ,
270
279
refHash : stateAt9 . txHash ,
271
280
refTxId : stateAt9 . txId ,
272
281
} )
273
282
console . log ( 'getTx8AndVerification' )
274
- console . log ( getTx8AndVerification , { depth : 10 } )
283
+ console . log ( getTx8AndVerification , { depth : 10 } )
275
284
console . log ( 'verifyVerification(getTx8AndVerification) result:' )
276
285
console . log ( verifyVerification ( getTx8AndVerification . verification ) )
277
-
286
+
278
287
279
288
280
289
0 commit comments