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 ( )
115const util = require ( 'util' )
2-
316const 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+
523ImmudbClient ( {
6- address : '127.0.0.1:3322' ,
7- } , main )
24+ address : ` ${ IMMUDB_HOST } : ${ IMMUDB_PORT } ` ,
25+ } , main )
826
927const 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