Skip to content

Commit da98670

Browse files
committed
2 parents 179f95f + b88f2f6 commit da98670

38 files changed

+3779
-15379
lines changed

.env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
IMMUDB_DEV_PATH=/path/to/immudb/repo
2+
IMMUDB_HOST=127.0.0.1
3+
IMMUDB_PORT=3322
4+
IMMUDB_TEST_PORT=56789
5+
IMMUDB_USER=immudb
6+
IMMUDB_PWD=immudb

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ test/immudb
55
.nyc_output
66
.vscode/
77
test/root.json
8+
.vscode
9+
rootfile

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,15 @@ Atomic multi-key write (all entries are persisted or none):
171171

172172
```
173173
req = {
174-
skvList: [{
174+
keys: [{
175175
key: 'key1',
176-
payload: 'value1',
177-
timestamp: Math.floor(Date.now()/100),
176+
payload: 'value1'
178177
},{
179178
key: 'key2',
180-
payload: 'value2',
181-
timestamp: Math.floor(Date.now()/100),
179+
payload: 'value2'
182180
}]
183181
}
184-
res = await cl.setBatchSV(req)
182+
res = await cl.setBatch(req)
185183
```
186184

187185
Atomic multi-key read (all entries are retrieved or none):
@@ -193,7 +191,7 @@ Atomic multi-key read (all entries are retrieved or none):
193191
key: 'key2',
194192
}],
195193
}
196-
res = await cl.getBatchSV(req)
194+
res = await cl.getBatch(req)
197195
```
198196

199197
### Closing the client

examples/.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
IMMUDB_HOST=127.0.0.1
2+
IMMUDB_PORT=3322
3+
IMMUDB_USER=immudb
4+
IMMUDB_PWD=immudb

examples/auth-management.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,46 @@
1+
/*
2+
Copyright 2019-2020 vChain, Inc.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
const dotenv = require('dotenv').config()
115
const ImmudbClient = require("../lib/client")
216
const types = require('../lib/types')
317

18+
const IMMUDB_HOST = process.env.IMMUDB_HOST || '127.0.0.1'
19+
const IMMUDB_PORT = process.env.IMMUDB_PORT || 3322
20+
const IMMUDB_USER = process.env.IMMUDB_USER || 'immudb'
21+
const IMMUDB_PWD = process.env.IMMUDB_PWD || 'immudb'
22+
423
ImmudbClient({
5-
address: '127.0.0.1:3322',
24+
address: `${IMMUDB_HOST}:${IMMUDB_PORT}`,
625
}, main)
726

8-
const rand = '' + Math.floor(Math.random()
9-
* Math.floor(100000))
10-
1127
async function main(err, cl) {
1228
if (err) {
1329
return console.log(err)
1430
}
1531

1632
try {
17-
let req = { username: 'immudb', password: 'immudb' }
33+
let req = { username: IMMUDB_USER, password: IMMUDB_PWD }
1834
let res = await cl.login(req)
1935

2036
res = await cl.useDatabase({ database: 'defaultdb' })
37+
console.log('success: useDatabase:', res)
2138

22-
await cl.updateAuthConfig({ auth: types.auth.enabled })
39+
res = await cl.updateAuthConfig({ auth: types.auth.enabled })
40+
console.log('success: updateAuthConfig')
2341

24-
await cl.updateMTLSConfig({ enabled: false })
42+
res = await cl.updateMTLSConfig({ enabled: false })
43+
console.log('success: updateMTLSConfig')
2544

2645
} catch (err) {
2746
console.log(err)

examples/batch-operations.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Copyright 2019-2020 vChain, Inc.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
const ImmudbClient = require('../lib/client')
15+
16+
const IMMUDB_HOST = process.env.IMMUDB_HOST || '127.0.0.1'
17+
const IMMUDB_PORT = process.env.IMMUDB_PORT || 3322
18+
const IMMUDB_USER = process.env.IMMUDB_USER || 'immudb'
19+
const IMMUDB_PWD = process.env.IMMUDB_PWD || 'immudb'
20+
21+
ImmudbClient({
22+
address: `${IMMUDB_HOST}:${IMMUDB_PORT}`,
23+
}, main)
24+
25+
const rand = '' + Math.floor(Math.random()
26+
* Math.floor(100000))
27+
28+
async function main(err, cl) {
29+
if (err) {
30+
return console.log(err)
31+
}
32+
33+
try {
34+
// login using the specified username and password
35+
let req = { username: IMMUDB_USER, password: IMMUDB_PWD }
36+
let res = await cl.login(req)
37+
console.log('success: login', res)
38+
39+
// create database
40+
req = { database: rand }
41+
res = await cl.createDatabase(req)
42+
console.log('success: createDatabase', res)
43+
44+
// use database just created
45+
req = { database: rand }
46+
res = await cl.useDatabase(req)
47+
console.log('success: useDatabase', res)
48+
49+
// execute a batch insert
50+
req = { keys: [] }
51+
for (let i = 0; i < 20; i++) {
52+
req.keys.push({ key: i, value: i })
53+
}
54+
res = await cl.setBatch(req)
55+
console.log(`success: setBatch`, res)
56+
57+
// execute a batch read
58+
req = { keys: [] }
59+
for (let i = 0; i < 20; i++) {
60+
req.keys.push({ key: i })
61+
}
62+
res = await cl.getBatch(req)
63+
console.log(`success: getBatch`, res)
64+
65+
} catch (err) {
66+
console.log(err)
67+
}
68+
}

examples/database-management.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
1+
/*
2+
Copyright 2019-2020 vChain, Inc.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
const dotenv = require('dotenv').config()
115
const util = require('util')
2-
316
const ImmudbClient = require('../lib/client')
417

18+
const IMMUDB_HOST = process.env.IMMUDB_HOST || '127.0.0.1'
19+
const IMMUDB_PORT = process.env.IMMUDB_PORT || 3322
20+
const IMMUDB_USER = process.env.IMMUDB_USER || 'immudb'
21+
const IMMUDB_PWD = process.env.IMMUDB_PWD || 'immudb'
22+
523
ImmudbClient({
6-
address: '127.0.0.1:3322',
7-
}, main)
24+
address: `${IMMUDB_HOST}:${IMMUDB_PORT}`,
25+
}, main)
826

927
const rand = '' + Math.floor(Math.random()
1028
* Math.floor(100000))
@@ -15,21 +33,27 @@ async function main(err, cl) {
1533
}
1634

1735
try {
18-
let req = { username: 'immudb', password: 'immudb' }
36+
let req = { username: IMMUDB_USER, password: IMMUDB_PWD }
1937
let res = await cl.login(req)
2038

2139
await cl.createDatabase({ database: rand })
40+
console.log('success: createDatabase', res);
2241

2342
res = await cl.useDatabase({ database: rand })
43+
console.log('success: useDatabase', res);
2444

2545
res = await cl.set({ key: rand, value: rand })
2646

2747
res = await cl.listDatabases()
48+
console.log('success: listDatabases', res);
49+
2850
console.log(util.inspect(res, false, 8, true))
2951

3052
res = await cl.printTree()
53+
console.log('success: printTree', res);
3154

3255
res = await cl.health()
56+
console.log('success: health', res);
3357

3458
} catch (err) {
3559
console.log(err)

0 commit comments

Comments
 (0)