Skip to content

Commit

Permalink
Merge pull request #32 from codenotary/publish-codenotary
Browse files Browse the repository at this point in the history
- Org scoped package
- new showcase
- zScan fix
  • Loading branch information
tomekkolo committed Oct 3, 2022
2 parents 929ebef + a42c70f commit a393703
Show file tree
Hide file tree
Showing 23 changed files with 713 additions and 92 deletions.
18 changes: 13 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,18 @@ jobs:
run: |
npm ci
npm run build
- name: Run immudb
- name: Run overview showcase
run: |
docker run -d --rm --health-cmd "immuadmin status" --health-interval 10s --health-timeout 5s --health-retries 5 -p 3322:3322 codenotary/immudb:latest
- name: Run showcase
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
npx ts-node --esm ./immudb-node-showcase/src/overview-showcase.ts
docker stop immudb
- name: Run sql showcase
run: |
cd immudb-node-showcase
npx ts-node --esm ./src/scanning.ts
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
npx ts-node --esm ./immudb-node-showcase/src/sql-showcase.ts
docker stop immudb
- name: Run zSet showcase
run: |
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
npx ts-node --esm ./immudb-node-showcase/src/zSet-showcase.ts
docker stop immudb
2 changes: 1 addition & 1 deletion immudb-node-doc/immudb-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ function myShowcase() {
Remember to have immudb docker image with exposed ports running:

```sh
docker run -d -it --rm -p 8080:8080 -p 3322:3322 -p 9497:9497 -p 5432:5432 --name immudb codenotary/immudb:latest
docker run -d -it --rm -p 8080:8080 -p 3322:3322 -p 9497:9497 -p 5432:5432 --name immudb codenotary/immudb:1.3.2
```
2 changes: 1 addition & 1 deletion immudb-node-doc/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "immudb-node-doc",
"name": "@codenotary/immudb-node-doc",
"version": "2.0.0-alpha.0",
"license": "Apache-2.0",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion immudb-node-grpcjs/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "immudb-node-grpcjs",
"name": "@codenotary/immudb-node-grpcjs",
"version": "2.0.0-alpha.0",
"license": "Apache-2.0",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion immudb-node-pbjs/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "immudb-node-pbjs",
"name": "@codenotary/immudb-node-pbjs",
"version": "2.0.0-alpha.0",
"license": "Apache-2.0",
"repository": {
Expand Down
24 changes: 17 additions & 7 deletions immudb-node-showcase/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,30 @@ npm install
```


Then run immudb docker image with exposed ports:


Then run showcase from (git) root directory (To have predictable output it is
best to restart immudb docker image before every showcase run):

```sh
docker run -d -it --rm -p 8080:8080 -p 3322:3322 -p 9497:9497 -p 5432:5432 --name immudb codenotary/immudb:latest
$ docker run -d -it --rm -p 8080:8080 -p 3322:3322 -p 9497:9497 -p 5432:5432 --name immudb codenotary/immudb:1.3.2
$ npx ts-node --esm ./immudb-node-showcase/src/overview-showcase.ts
$ docker stop immudb
```

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

```sh
npx ts-node --esm .\src\scanning.ts
$ docker run -d -it --rm -p 8080:8080 -p 3322:3322 -p 9497:9497 -p 5432:5432 --name immudb codenotary/immudb:1.3.2
$ npx ts-node --esm ./immudb-node-showcase/src/zSet-showcase.ts
$ docker stop immudb
```

To have predictable output it is best to restart immudb docker image
before every showcase run.


## Create your own showcase and experiment

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

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


Expand Down
4 changes: 2 additions & 2 deletions immudb-node-showcase/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "immudb-node-showcase",
"name": "@codenotary/immudb-node-showcase",
"version": "2.0.0-alpha.0",
"license": "Apache-2.0",
"repository": {
Expand All @@ -19,7 +19,7 @@
}
},
"dependencies": {
"immudb-node": "2.0.0-alpha.0",
"@codenotary/immudb-node": "2.0.0-alpha.0",
"long": "^5.2.0"
},
"devDependencies": {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ import {



scanningShowcase()
overviewSchowcase()
.catch(console.error)






async function scanningShowcase() {
async function overviewSchowcase() {


const client = new Client({
Expand Down Expand Up @@ -236,7 +232,7 @@ async function scanningShowcase() {
refTxId: stateAt9.txId,
})
console.log('getTx2AndVerification')
console.dir(getTx2AndVerification, {depth: 10})
console.log(getTx2AndVerification, {depth: 10})
console.log('verifyVerification(getTx2AndVerification) result:')
console.log(verifyVerification(getTx2AndVerification.verification))

Expand All @@ -250,7 +246,7 @@ async function scanningShowcase() {
refTxId: stateAt9.txId,
})
console.log('getTx6AndVerification')
console.dir(getTx6AndVerification, {depth: 10})
console.log(getTx6AndVerification, {depth: 10})
console.log('verifyVerification(getTx6AndVerification) result:')
console.log(verifyVerification(getTx6AndVerification.verification))

Expand All @@ -263,7 +259,7 @@ async function scanningShowcase() {
refTxId: stateAt9.txId,
})
console.log('getTx7AndVerification')
console.dir(getTx7AndVerification, {depth: 10})
console.log(getTx7AndVerification, {depth: 10})
console.log('verifyVerification(getTx7AndVerification) result:')
console.log(verifyVerification(getTx7AndVerification.verification))

Expand All @@ -275,7 +271,7 @@ async function scanningShowcase() {
refTxId: stateAt9.txId,
})
console.log('getTx8AndVerification')
console.dir(getTx8AndVerification, {depth: 10})
console.log(getTx8AndVerification, {depth: 10})
console.log('verifyVerification(getTx8AndVerification) result:')
console.log(verifyVerification(getTx8AndVerification.verification))

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







await client.close()
}

Expand Down
139 changes: 139 additions & 0 deletions immudb-node-showcase/src/sql-showcase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/**
* Run with:
*
* ```sh
* npx ts-node --esm .\immudb-node-showcase\src\sql-showcase.ts
* ```
*/
import Long from 'long'
import {
Client,
verifyVerification,
types,
stream,
} from 'immudb-node'





sqlSchowcase()
.catch(console.error)

async function sqlSchowcase() {

const client = new Client({
host: '127.0.0.1',
port: 3322,
user: 'immudb',
password: 'immudb',
database: 'defaultdb',
})

// since tx used for verification reference
// cannot be first db transaction lets insert some dummy value:
const {valEntries: [dummyValEntry]} = await client.setValEntries({kvms: [
{key: Buffer.of(0), val: Buffer.of(0)}
]})

// state will be dummyValEntry if database was empty
const stateId2 = await client.getDbCurrentState()
console.log('stateId2:', stateId2)


const {subTxes: [{tx: createTestTableTx}]} = await client.sqlExec({sql: `
create table if not exists testtable (
id1 integer not null,
id2 varchar[3] null,
created timestamp null,
data varchar[512] not null,
isActive boolean not null,
primary key (id1, id2)
);
`})
console.log('createTestTableTx:', createTestTableTx)


const {subTxes: [{
tx: insertTestTableTx,
lastPK: insertTestTableLastPK,
firstPK: insertTestTableFirstPK,
updatedRowsCount: insertTestTableUpdatedRowsCount
}]} = await client.sqlExec({sql: `
upsert into testtable
(id1, id2, created, data, isactive)
values
(-2, 'kkk', NOW(), 'upsert existing', true),
(10, 'yoy', NOW(), 'upsert operation 2', false),
(11, 'qoy', NOW(), 'upsert operation 3', true);
`})
console.log('insertTestTableTx:', insertTestTableTx)
console.log('insertTestTableLastPK:', insertTestTableLastPK)
console.log('insertTestTableFirstPK:', insertTestTableFirstPK)
console.log('insertTestTableUpdatedRowsCount:', insertTestTableUpdatedRowsCount)

// state at last sql insert (assuming empty db)
const stateId4 = await client.getDbCurrentState()
console.log('stateId4:', stateId4)


const {valEntries: [dummyValEntry1]} = await client.setValEntries({kvms: [
{key: Buffer.of(0), val: Buffer.of(1)}
]})

// state 1 transactions after last sql insert (assuming empty db)
const stateId5 = await client.getDbCurrentState()
console.log('stateId5:', stateId5)


const {valEntries: [dummyValEntry2]} = await client.setValEntries({kvms: [
{key: Buffer.of(0), val: Buffer.of(2)}
]})

// state 2 transactions after last sql insert (assuming empty db)
const stateId6 = await client.getDbCurrentState()
console.log('stateId6:', stateId6)




if(createTestTableTx) {
const createTestTableTxVer = await client.getTxAndVerification({
txId: createTestTableTx.id,
refHash: stateId5.txHash,
refTxId: stateId5.txId,
})
verifyVerification(createTestTableTxVer.verification)
console.log('createTestTableTxVer has been verified.')
}



if(insertTestTableTx) {
const insertTestTableTxVer = await client.getTxAndVerification({
txId: insertTestTableTx.id,
refHash: stateId5.txHash,
refTxId: stateId5.txId,
})
verifyVerification(insertTestTableTxVer.verification)
console.log('insertTestTableTxVer has been verified.')
// console.log('insertTestTableTxVer')
// console.log(insertTestTableTxVer, {depth: 10})



// await client.getSqlRowEntryAndVerification({
// pk: is.encodeAsPK([
// {type: 'INTEGER', isNotNullable: true, val: -2},
// {type: 'VARCHAR', isNotNullable: false, val: 'kkk'},
// ])
// })
}



console.log('dbScan:', await client.scanDbEntries())


await client.close()
}
Loading

0 comments on commit a393703

Please sign in to comment.