Skip to content

Commit a393703

Browse files
authored
Merge pull request #32 from codenotary/publish-codenotary
- Org scoped package - new showcase - zScan fix
2 parents 929ebef + a42c70f commit a393703

File tree

23 files changed

+713
-92
lines changed

23 files changed

+713
-92
lines changed

.github/workflows/build.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,18 @@ jobs:
2727
run: |
2828
npm ci
2929
npm run build
30-
- name: Run immudb
30+
- name: Run overview showcase
3131
run: |
32-
docker run -d --rm --health-cmd "immuadmin status" --health-interval 10s --health-timeout 5s --health-retries 5 -p 3322:3322 codenotary/immudb:latest
33-
- name: Run showcase
32+
docker run -d --rm --health-cmd "immuadmin status" --health-interval 10s --health-timeout 5s --health-retries 5 -p 3322:3322 --name immudb codenotary/immudb:1.3.2
33+
npx ts-node --esm ./immudb-node-showcase/src/overview-showcase.ts
34+
docker stop immudb
35+
- name: Run sql showcase
3436
run: |
35-
cd immudb-node-showcase
36-
npx ts-node --esm ./src/scanning.ts
37+
docker run -d --rm --health-cmd "immuadmin status" --health-interval 10s --health-timeout 5s --health-retries 5 -p 3322:3322 --name immudb codenotary/immudb:1.3.2
38+
npx ts-node --esm ./immudb-node-showcase/src/sql-showcase.ts
39+
docker stop immudb
40+
- name: Run zSet showcase
41+
run: |
42+
docker run -d --rm --health-cmd "immuadmin status" --health-interval 10s --health-timeout 5s --health-retries 5 -p 3322:3322 --name immudb codenotary/immudb:1.3.2
43+
npx ts-node --esm ./immudb-node-showcase/src/zSet-showcase.ts
44+
docker stop immudb

immudb-node-doc/immudb-node/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ function myShowcase() {
3535
Remember to have immudb docker image with exposed ports running:
3636

3737
```sh
38-
docker run -d -it --rm -p 8080:8080 -p 3322:3322 -p 9497:9497 -p 5432:5432 --name immudb codenotary/immudb:latest
38+
docker run -d -it --rm -p 8080:8080 -p 3322:3322 -p 9497:9497 -p 5432:5432 --name immudb codenotary/immudb:1.3.2
3939
```

immudb-node-doc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "immudb-node-doc",
2+
"name": "@codenotary/immudb-node-doc",
33
"version": "2.0.0-alpha.0",
44
"license": "Apache-2.0",
55
"repository": {

immudb-node-grpcjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "immudb-node-grpcjs",
2+
"name": "@codenotary/immudb-node-grpcjs",
33
"version": "2.0.0-alpha.0",
44
"license": "Apache-2.0",
55
"repository": {

immudb-node-pbjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "immudb-node-pbjs",
2+
"name": "@codenotary/immudb-node-pbjs",
33
"version": "2.0.0-alpha.0",
44
"license": "Apache-2.0",
55
"repository": {

immudb-node-showcase/README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,30 @@ npm install
1515
```
1616

1717

18-
Then run immudb docker image with exposed ports:
18+
19+
20+
Then run showcase from (git) root directory (To have predictable output it is
21+
best to restart immudb docker image before every showcase run):
1922

2023
```sh
21-
docker run -d -it --rm -p 8080:8080 -p 3322:3322 -p 9497:9497 -p 5432:5432 --name immudb codenotary/immudb:latest
24+
$ docker run -d -it --rm -p 8080:8080 -p 3322:3322 -p 9497:9497 -p 5432:5432 --name immudb codenotary/immudb:1.3.2
25+
$ npx ts-node --esm ./immudb-node-showcase/src/overview-showcase.ts
26+
$ docker stop immudb
2227
```
2328

24-
Then run example, e.g.:
29+
```sh
30+
$ docker run -d -it --rm -p 8080:8080 -p 3322:3322 -p 9497:9497 -p 5432:5432 --name immudb codenotary/immudb:1.3.2
31+
$ npx ts-node --esm ./immudb-node-showcase/src/sql-showcase.ts
32+
$ docker stop immudb
33+
```
2534

2635
```sh
27-
npx ts-node --esm .\src\scanning.ts
36+
$ docker run -d -it --rm -p 8080:8080 -p 3322:3322 -p 9497:9497 -p 5432:5432 --name immudb codenotary/immudb:1.3.2
37+
$ npx ts-node --esm ./immudb-node-showcase/src/zSet-showcase.ts
38+
$ docker stop immudb
2839
```
2940

30-
To have predictable output it is best to restart immudb docker image
31-
before every showcase run.
41+
3242

3343
## Create your own showcase and experiment
3444

@@ -68,7 +78,7 @@ function myShowcase() {
6878
Remember to have your immudb instance running:
6979

7080
```sh
71-
docker run -d -it --rm -p 8080:8080 -p 3322:3322 -p 9497:9497 -p 5432:5432 --name immudb codenotary/immudb:latest
81+
docker run -d -it --rm -p 8080:8080 -p 3322:3322 -p 9497:9497 -p 5432:5432 --name immudb codenotary/immudb:1.3.2
7282
```
7383

7484

immudb-node-showcase/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "immudb-node-showcase",
2+
"name": "@codenotary/immudb-node-showcase",
33
"version": "2.0.0-alpha.0",
44
"license": "Apache-2.0",
55
"repository": {
@@ -19,7 +19,7 @@
1919
}
2020
},
2121
"dependencies": {
22-
"immudb-node": "2.0.0-alpha.0",
22+
"@codenotary/immudb-node": "2.0.0-alpha.0",
2323
"long": "^5.2.0"
2424
},
2525
"devDependencies": {
File renamed without changes.

immudb-node-showcase/src/scanning.ts renamed to immudb-node-showcase/src/overview-showcase.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@ import {
1010

1111

1212

13-
scanningShowcase()
13+
overviewSchowcase()
1414
.catch(console.error)
1515

1616

17-
18-
19-
20-
21-
async function scanningShowcase() {
17+
async function overviewSchowcase() {
2218

2319

2420
const client = new Client({
@@ -236,7 +232,7 @@ async function scanningShowcase() {
236232
refTxId: stateAt9.txId,
237233
})
238234
console.log('getTx2AndVerification')
239-
console.dir(getTx2AndVerification, {depth: 10})
235+
console.log(getTx2AndVerification, {depth: 10})
240236
console.log('verifyVerification(getTx2AndVerification) result:')
241237
console.log(verifyVerification(getTx2AndVerification.verification))
242238

@@ -250,7 +246,7 @@ async function scanningShowcase() {
250246
refTxId: stateAt9.txId,
251247
})
252248
console.log('getTx6AndVerification')
253-
console.dir(getTx6AndVerification, {depth: 10})
249+
console.log(getTx6AndVerification, {depth: 10})
254250
console.log('verifyVerification(getTx6AndVerification) result:')
255251
console.log(verifyVerification(getTx6AndVerification.verification))
256252

@@ -263,7 +259,7 @@ async function scanningShowcase() {
263259
refTxId: stateAt9.txId,
264260
})
265261
console.log('getTx7AndVerification')
266-
console.dir(getTx7AndVerification, {depth: 10})
262+
console.log(getTx7AndVerification, {depth: 10})
267263
console.log('verifyVerification(getTx7AndVerification) result:')
268264
console.log(verifyVerification(getTx7AndVerification.verification))
269265

@@ -275,7 +271,7 @@ async function scanningShowcase() {
275271
refTxId: stateAt9.txId,
276272
})
277273
console.log('getTx8AndVerification')
278-
console.dir(getTx8AndVerification, {depth: 10})
274+
console.log(getTx8AndVerification, {depth: 10})
279275
console.log('verifyVerification(getTx8AndVerification) result:')
280276
console.log(verifyVerification(getTx8AndVerification.verification))
281277

@@ -284,10 +280,6 @@ async function scanningShowcase() {
284280

285281

286282

287-
288-
289-
290-
291283
await client.close()
292284
}
293285

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/**
2+
* Run with:
3+
*
4+
* ```sh
5+
* npx ts-node --esm .\immudb-node-showcase\src\sql-showcase.ts
6+
* ```
7+
*/
8+
import Long from 'long'
9+
import {
10+
Client,
11+
verifyVerification,
12+
types,
13+
stream,
14+
} from 'immudb-node'
15+
16+
17+
18+
19+
20+
sqlSchowcase()
21+
.catch(console.error)
22+
23+
async function sqlSchowcase() {
24+
25+
const client = new Client({
26+
host: '127.0.0.1',
27+
port: 3322,
28+
user: 'immudb',
29+
password: 'immudb',
30+
database: 'defaultdb',
31+
})
32+
33+
// since tx used for verification reference
34+
// cannot be first db transaction lets insert some dummy value:
35+
const {valEntries: [dummyValEntry]} = await client.setValEntries({kvms: [
36+
{key: Buffer.of(0), val: Buffer.of(0)}
37+
]})
38+
39+
// state will be dummyValEntry if database was empty
40+
const stateId2 = await client.getDbCurrentState()
41+
console.log('stateId2:', stateId2)
42+
43+
44+
const {subTxes: [{tx: createTestTableTx}]} = await client.sqlExec({sql: `
45+
create table if not exists testtable (
46+
id1 integer not null,
47+
id2 varchar[3] null,
48+
created timestamp null,
49+
data varchar[512] not null,
50+
isActive boolean not null,
51+
primary key (id1, id2)
52+
);
53+
`})
54+
console.log('createTestTableTx:', createTestTableTx)
55+
56+
57+
const {subTxes: [{
58+
tx: insertTestTableTx,
59+
lastPK: insertTestTableLastPK,
60+
firstPK: insertTestTableFirstPK,
61+
updatedRowsCount: insertTestTableUpdatedRowsCount
62+
}]} = await client.sqlExec({sql: `
63+
upsert into testtable
64+
(id1, id2, created, data, isactive)
65+
values
66+
(-2, 'kkk', NOW(), 'upsert existing', true),
67+
(10, 'yoy', NOW(), 'upsert operation 2', false),
68+
(11, 'qoy', NOW(), 'upsert operation 3', true);
69+
`})
70+
console.log('insertTestTableTx:', insertTestTableTx)
71+
console.log('insertTestTableLastPK:', insertTestTableLastPK)
72+
console.log('insertTestTableFirstPK:', insertTestTableFirstPK)
73+
console.log('insertTestTableUpdatedRowsCount:', insertTestTableUpdatedRowsCount)
74+
75+
// state at last sql insert (assuming empty db)
76+
const stateId4 = await client.getDbCurrentState()
77+
console.log('stateId4:', stateId4)
78+
79+
80+
const {valEntries: [dummyValEntry1]} = await client.setValEntries({kvms: [
81+
{key: Buffer.of(0), val: Buffer.of(1)}
82+
]})
83+
84+
// state 1 transactions after last sql insert (assuming empty db)
85+
const stateId5 = await client.getDbCurrentState()
86+
console.log('stateId5:', stateId5)
87+
88+
89+
const {valEntries: [dummyValEntry2]} = await client.setValEntries({kvms: [
90+
{key: Buffer.of(0), val: Buffer.of(2)}
91+
]})
92+
93+
// state 2 transactions after last sql insert (assuming empty db)
94+
const stateId6 = await client.getDbCurrentState()
95+
console.log('stateId6:', stateId6)
96+
97+
98+
99+
100+
if(createTestTableTx) {
101+
const createTestTableTxVer = await client.getTxAndVerification({
102+
txId: createTestTableTx.id,
103+
refHash: stateId5.txHash,
104+
refTxId: stateId5.txId,
105+
})
106+
verifyVerification(createTestTableTxVer.verification)
107+
console.log('createTestTableTxVer has been verified.')
108+
}
109+
110+
111+
112+
if(insertTestTableTx) {
113+
const insertTestTableTxVer = await client.getTxAndVerification({
114+
txId: insertTestTableTx.id,
115+
refHash: stateId5.txHash,
116+
refTxId: stateId5.txId,
117+
})
118+
verifyVerification(insertTestTableTxVer.verification)
119+
console.log('insertTestTableTxVer has been verified.')
120+
// console.log('insertTestTableTxVer')
121+
// console.log(insertTestTableTxVer, {depth: 10})
122+
123+
124+
125+
// await client.getSqlRowEntryAndVerification({
126+
// pk: is.encodeAsPK([
127+
// {type: 'INTEGER', isNotNullable: true, val: -2},
128+
// {type: 'VARCHAR', isNotNullable: false, val: 'kkk'},
129+
// ])
130+
// })
131+
}
132+
133+
134+
135+
console.log('dbScan:', await client.scanDbEntries())
136+
137+
138+
await client.close()
139+
}

0 commit comments

Comments
 (0)