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,17 @@ 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
163
console . log ( sqlQueryInTxAt8 )
161
164
162
165
163
166
// sqlExecUpsert9
164
- const sqlExecUpsertInTx9 = txApi . exec ( { sql :`
167
+ const sqlExecUpsertInTx9 = txApi . exec ( {
168
+ sql : `
165
169
upsert into testtable
166
170
(id1, id2, created, data, isactive)
167
171
values
@@ -170,7 +174,8 @@ async function overviewSchowcase() {
170
174
` } )
171
175
172
176
173
- const sqlQueryInTxAt9 = await txApi . query ( { sql : `
177
+ const sqlQueryInTxAt9 = await txApi . query ( {
178
+ sql : `
174
179
select * from testtable;
175
180
` } )
176
181
console . log ( 'sqlQueryInTxAt9' )
@@ -184,18 +189,19 @@ async function overviewSchowcase() {
184
189
console . log ( sqlTxAt8 )
185
190
186
191
187
- const sqlQueryAt8 = await client . sqlQuery ( { sql : `
192
+ const sqlQueryAt8 = await client . sqlQuery ( {
193
+ sql : `
188
194
select * from testtable;
189
195
` } )
190
196
console . log ( 'sqlQueryInTxAt8' )
191
197
console . log ( sqlQueryAt8 )
192
- const k = sqlQueryAt8 [ 0 ]
193
- const d = k [ 0 ]
194
-
195
-
198
+
199
+ const row = await sqlQueryAt8 . next ( )
200
+ console . log ( row )
201
+
196
202
197
203
const dbScanAt8 = await client . scanDbEntries ( {
198
- scanStartAtTxId : Long . fromValue ( 1 , true ) ,
204
+ scanStartAtTxId : Long . fromValue ( 1 , true ) ,
199
205
} )
200
206
console . log ( 'dbScanAt8' )
201
207
console . log ( dbScanAt8 )
@@ -208,12 +214,12 @@ async function overviewSchowcase() {
208
214
209
215
210
216
const setAndProof9 = await client . setValEntriesGetVerification ( {
211
- kvms : [ { key : Buffer . from ( 'yo' ) , val : Buffer . from ( 'man' ) } ] ,
217
+ kvms : [ { key : Buffer . from ( 'yo' ) , val : Buffer . from ( 'man' ) } ] ,
212
218
refTxId : stateAt8 . txId ,
213
219
refHash : stateAt8 . txHash ,
214
220
} )
215
221
console . log ( 'setAndProof9' )
216
- console . dir ( setAndProof9 , { depth : 10 } )
222
+ console . dir ( setAndProof9 , { depth : 10 } )
217
223
218
224
console . log ( 'verifyVerification(setAndProof9) result:' )
219
225
console . log ( verifyVerification ( setAndProof9 . verification ) )
@@ -232,7 +238,7 @@ async function overviewSchowcase() {
232
238
refTxId : stateAt9 . txId ,
233
239
} )
234
240
console . log ( 'getTx2AndVerification' )
235
- console . log ( getTx2AndVerification , { depth : 10 } )
241
+ console . log ( getTx2AndVerification , { depth : 10 } )
236
242
console . log ( 'verifyVerification(getTx2AndVerification) result:' )
237
243
console . log ( verifyVerification ( getTx2AndVerification . verification ) )
238
244
@@ -241,40 +247,40 @@ async function overviewSchowcase() {
241
247
242
248
// entries6
243
249
const getTx6AndVerification = await client . getTxAndVerification ( {
244
- txId : entries6 . tx . id ,
250
+ txId : entries6 . tx . id ,
245
251
refHash : stateAt9 . txHash ,
246
252
refTxId : stateAt9 . txId ,
247
253
} )
248
254
console . log ( 'getTx6AndVerification' )
249
- console . log ( getTx6AndVerification , { depth : 10 } )
255
+ console . log ( getTx6AndVerification , { depth : 10 } )
250
256
console . log ( 'verifyVerification(getTx6AndVerification) result:' )
251
257
console . log ( verifyVerification ( getTx6AndVerification . verification ) )
252
258
253
259
254
260
255
261
// sqlExecCreateTable7.subTxes[0].tx?.id
256
262
const getTx7AndVerification = await client . getTxAndVerification ( {
257
- txId : Long . fromInt ( 7 , true ) ,
263
+ txId : Long . fromInt ( 7 , true ) ,
258
264
refHash : stateAt9 . txHash ,
259
265
refTxId : stateAt9 . txId ,
260
266
} )
261
267
console . log ( 'getTx7AndVerification' )
262
- console . log ( getTx7AndVerification , { depth : 10 } )
268
+ console . log ( getTx7AndVerification , { depth : 10 } )
263
269
console . log ( 'verifyVerification(getTx7AndVerification) result:' )
264
270
console . log ( verifyVerification ( getTx7AndVerification . verification ) )
265
271
266
272
267
273
// sqlExecUpsert8
268
274
const getTx8AndVerification = await client . getTxAndVerification ( {
269
- txId : Long . fromInt ( 8 , true ) ,
275
+ txId : Long . fromInt ( 8 , true ) ,
270
276
refHash : stateAt9 . txHash ,
271
277
refTxId : stateAt9 . txId ,
272
278
} )
273
279
console . log ( 'getTx8AndVerification' )
274
- console . log ( getTx8AndVerification , { depth : 10 } )
280
+ console . log ( getTx8AndVerification , { depth : 10 } )
275
281
console . log ( 'verifyVerification(getTx8AndVerification) result:' )
276
282
console . log ( verifyVerification ( getTx8AndVerification . verification ) )
277
-
283
+
278
284
279
285
280
286
0 commit comments