11'use strict'
22
33
4- const co = require ( 'co' )
4+
55const ChainsqlAPI = require ( '../src/index' ) ;
66const r = new ChainsqlAPI ( ) ;
77var path = require ( 'path' ) ;
@@ -10,11 +10,12 @@ var common = require(basePath);
1010var crypto = require ( '../lib/crypto' ) ;
1111const keypairs = require ( 'chainsql-keypairs-test' ) ;
1212
13- co ( function * ( ) {
13+ main ( ) ;
14+ async function main ( ) {
1415 try {
15- // yield r.connect('ws://127.0.0.1:6007');
16- //yield r.connect('ws://139.198.11.189:6006');
17- yield r . connect ( 'ws://192.168.0.14:6006' ) ;
16+ // await r.connect('ws://127.0.0.1:6007');
17+ //await r.connect('ws://139.198.11.189:6006');
18+ await r . connect ( 'ws://192.168.0.14:6006' ) ;
1819 // console.log('连接成功')
1920 // var tb = 'test13323333';
2021
@@ -24,7 +25,7 @@ co(function*() {
2425 // });
2526 // r.setRestrict(true);
2627
27- // // var data = yield r.api.getLedger();
28+ // // var data = await r.api.getLedger();
2829 // // console.log(data);
2930 // r.api.getLedger({ledgerVersion:1732000}).then(function(data){
3031 // console.log(data);
@@ -41,11 +42,11 @@ co(function*() {
4142 //字段级加密
4243 console . log ( "multi encrypt test:" ) ;
4344 var listPublic = [ "cBP7JPfSVPgqGfGXVJVw168sJU5HhQfPbvDRZyriyKNeYjYLVL8M" , "cBPaLRSCwtsJbz4Rq4K2NvoiDZWJyL2RnfdGv5CQ2UFWqyJ7ekHM" ] ;
44- var cip = yield crypto . encryptText ( "test" , listPublic ) ;
45+ var cip = await crypto . encryptText ( "test" , listPublic ) ;
4546 console . log ( "cipher:" + cip ) ;
46- var text = yield crypto . decryptText ( cip , "xpvPjSRCtmQ3G99Pfu1VMDMd9ET3W" ) ;
47+ var text = await crypto . decryptText ( cip , "xpvPjSRCtmQ3G99Pfu1VMDMd9ET3W" ) ;
4748 console . log ( "plain text:" + text ) ;
48- var text2 = yield crypto . decryptText ( cip , "xnHAcvtn1eVLDskhxPKNrhTsYKqde" ) ;
49+ var text2 = await crypto . decryptText ( cip , "xnHAcvtn1eVLDskhxPKNrhTsYKqde" ) ;
4950 console . log ( "plain text2:" + text2 ) ;
5051
5152
@@ -57,7 +58,7 @@ co(function*() {
5758
5859
5960 // 创建表
60- let rs = yield r . createTable ( "abc" , [ {
61+ let rs = await r . createTable ( "abc" , [ {
6162 "field" : "id" ,
6263 "type" : "int" ,
6364 "length" : 11 ,
@@ -75,47 +76,47 @@ co(function*() {
7576 // console.log(rs)
7677
7778 // 删除表
78- // let rs = yield r.drop(tb);
79+ // let rs = await r.drop(tb);
7980
8081 // 重命名
81- // let rs = yield r.rename(tb,'users');
82+ // let rs = await r.rename(tb,'users');
8283 // 授权权限
83- // let rs = yield r.assign(tb, 'rETMNdu2UgPhLZzbnDUVRHhB6NEDahj53c', [r.perm.insert],'0330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD02');
84+ // let rs = await r.assign(tb, 'rETMNdu2UgPhLZzbnDUVRHhB6NEDahj53c', [r.perm.insert],'0330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD02');
8485 // console.log(rs)
8586 //取消授权
86- // let rs = yield r.assignCancle('users', 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', ['lsfUpdate']);
87+ // let rs = await r.assignCancle('users', 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', ['lsfUpdate']);
8788 // 插入数据
88- //let rs = yield r.table(tb).insert({name:'xiaopeng'}).submit();
89- // let rs = yield r.table(tb).insert({name:'feipeng1'}).submit();
89+ //let rs = await r.table(tb).insert({name:'xiaopeng'}).submit();
90+ // let rs = await r.table(tb).insert({name:'feipeng1'}).submit();
9091 //删除数据
91- // let rs = yield r.table(tb).get({id:1}).delete().submit();
92+ // let rs = await r.table(tb).get({id:1}).delete().submit();
9293 // 获取数据
93- //let rs = yield r.table(tb).get(['id','name']).submit();
94+ //let rs = await r.table(tb).get(['id','name']).submit();
9495
9596 // 测试一个条件的情况
96- //let rs = yield r.table(tb).get({id:{$ge:1}}).withFields(['id','name']).submit();
97+ //let rs = await r.table(tb).get({id:{$ge:1}}).withFields(['id','name']).submit();
9798
9899 // // 测试 or 条件
99- //let rs = yield r.table(tb).get({id:{$eq:1}},{name:'feipeng1'}).withFields(['id','name']).submit();
100- //let rs = yield r.table(tb).get({id:{$eq:1}},{name:{$eq:'feipeng1'}}).withFields(['id','name']).submit();
101- //let rs = yield r.table(tb).get({$or:[{id:{$ge:1}},{name:'feipeng1'}] }).withFields(['id','name']).submit();
100+ //let rs = await r.table(tb).get({id:{$eq:1}},{name:'feipeng1'}).withFields(['id','name']).submit();
101+ //let rs = await r.table(tb).get({id:{$eq:1}},{name:{$eq:'feipeng1'}}).withFields(['id','name']).submit();
102+ //let rs = await r.table(tb).get({$or:[{id:{$ge:1}},{name:'feipeng1'}] }).withFields(['id','name']).submit();
102103
103104 // 测试 and 条件
104- //let rs = yield r.table(tb).get({$and:[{id:{$ge:1}},{name:'feipeng1'}] }).withFields(['id','name']).submit();
105- //let rs = yield r.table(tb).get([{id:{$ge:1},name:'feipeng1'}]).withFields(['id','name']).submit();
106- //let rs = yield r.table(tb).get([{id:{$ge:1},name:{$eq:'feipeng1'}}]).withFields(['id','name']).submit();
105+ //let rs = await r.table(tb).get({$and:[{id:{$ge:1}},{name:'feipeng1'}] }).withFields(['id','name']).submit();
106+ //let rs = await r.table(tb).get([{id:{$ge:1},name:'feipeng1'}]).withFields(['id','name']).submit();
107+ //let rs = await r.table(tb).get([{id:{$ge:1},name:{$eq:'feipeng1'}}]).withFields(['id','name']).submit();
107108
108109 // 测试 limit
109- //let rs = yield r.table(tb).get({id:{$eq:1}},{name:'feipeng1'},{$limit:{index:0,total:1}}).withFields(['id','name']).submit();
110+ //let rs = await r.table(tb).get({id:{$eq:1}},{name:'feipeng1'},{$limit:{index:0,total:1}}).withFields(['id','name']).submit();
110111 // order by asc
111- //let rs = yield r.table(tb).get({id:{$eq:1}},{name:'feipeng1'},{$limit:{index:0,total:2},$order:[{id:1}]}).withFields(['id','name']).submit();
112+ //let rs = await r.table(tb).get({id:{$eq:1}},{name:'feipeng1'},{$limit:{index:0,total:2},$order:[{id:1}]}).withFields(['id','name']).submit();
112113 // order by desc
113- // let rs = yield r.table(tb).get({id:{$eq:1}},{name:'feipeng1'},{$limit:{index:0,total:2},$order:[{id:-1}]}).withFields(['id','name']).submit();
114+ // let rs = await r.table(tb).get({id:{$eq:1}},{name:'feipeng1'},{$limit:{index:0,total:2},$order:[{id:-1}]}).withFields(['id','name']).submit();
114115
115116 //更新数据
116- // let rs = yield r.table(tb).update({name:'xiaopeng'},{id:2}).submit();
117+ // let rs = await r.table(tb).update({name:'xiaopeng'},{id:2}).submit();
117118 // 获取所有交易
118- // let rs = yield r.getTransactions({limit:10,types:['sqlStatement']});
119+ // let rs = await r.getTransactions({limit:10,types:['sqlStatement']});
119120 //
120121 // console.log(rs)
121122 // 事务操作
@@ -143,11 +144,9 @@ co(function*() {
143144 // }],{confidential:true});
144145 // r.table(tb).insert({id:33,name:'xiaopeng454'});
145146 // r.table(tb).insert({id:34,name:'feipeng14544'});
146- // var data = yield r.commit();
147+ // var data = await r.commit();
147148 // console.log('data',data)
148149 } catch ( e ) {
149150 console . log ( e )
150151 }
151- } )
152-
153- console . log ( "llls" )
152+ }
0 commit comments