@@ -25,7 +25,6 @@ const getSequence = util.getSequence;
2525const convertStringToHex = util . convertStringToHex ;
2626const getTableSequence = util . getTableSequence ;
2727const getUserToken = util . getUserToken ;
28- const getTableName = util . getTableName ;
2928const getTxJson = util . getTxJson ;
3029const generateToken = util . generateToken ;
3130const decodeToken = util . decodeToken ;
@@ -785,11 +784,17 @@ ChainsqlAPI.prototype.signFor = function (json, secret, option) {
785784
786785ChainsqlAPI . prototype . getAccountTables = function ( address , bGetDetailInfo = false ) {
787786 var connection = this . api ? this . api . connection : this . connect . api . connection ;
788- return connection . request ( {
789- command : 'g_accountTables' ,
790- account : address ,
791- detail : bGetDetailInfo
792- } ) ;
787+ return new Promise ( function ( resolve , reject ) {
788+ connection . request ( {
789+ command : 'g_accountTables' ,
790+ account : address ,
791+ detail : bGetDetailInfo
792+ } ) . then ( function ( data ) {
793+ dealWithRet ( data , resolve , reject ) ;
794+ } ) . catch ( function ( err ) {
795+ reject ( err ) ;
796+ } )
797+ } )
793798}
794799
795800ChainsqlAPI . prototype . getTableAuth = function ( owner , tableName , accounts ) {
@@ -802,19 +807,49 @@ ChainsqlAPI.prototype.getTableAuth = function(owner,tableName,accounts){
802807 if ( accounts && accounts . length > 0 ) {
803808 req . accounts = accounts ;
804809 }
805- return connection . request ( req ) ;
810+ return new Promise ( function ( resolve , reject ) {
811+ connection . request ( req ) . then ( function ( data ) {
812+ dealWithRet ( data , resolve , reject ) ;
813+ } ) . catch ( function ( err ) {
814+ reject ( err ) ;
815+ } )
816+ } )
806817}
807818
819+ function dealWithRet ( data , resolve , reject ) {
820+ if ( data . status == 'success' ) {
821+ resolve ( data ) ;
822+ } else {
823+ reject ( data ) ;
824+ }
825+ }
808826ChainsqlAPI . prototype . getTableNameInDB = function ( owner , tableName ) {
809- return util . getTableName ( this , owner , tableName ) ;
827+ var that = this ;
828+ return new Promise ( function ( resolve , reject ) {
829+ util . getTableName ( that , owner , tableName ) . then ( function ( data ) {
830+ if ( data . status == 'success' ) {
831+ resolve ( data . nameInDB ) ;
832+ } else {
833+ reject ( data ) ;
834+ }
835+ } ) . catch ( function ( err ) {
836+ reject ( err ) ;
837+ } )
838+ } )
810839}
811840
812841ChainsqlAPI . prototype . getBySqlAdmin = function ( sql ) {
813842 var connection = this . api ? this . api . connection : this . connect . api . connection ;
814- return connection . request ( {
815- command : 'r_get_sql_admin' ,
816- sql :sql
817- } ) ;
843+ return new Promise ( function ( resolve , reject ) {
844+ connection . request ( {
845+ command : 'r_get_sql_admin' ,
846+ sql :sql
847+ } ) . then ( function ( data ) {
848+ dealWithRet ( data , resolve , reject ) ;
849+ } ) . catch ( function ( err ) {
850+ reject ( err ) ;
851+ } )
852+ } )
818853}
819854
820855ChainsqlAPI . prototype . getBySqlUser = function ( sql ) {
@@ -836,9 +871,9 @@ ChainsqlAPI.prototype.getBySqlUser = function(sql){
836871 tx_json :json
837872 } )
838873 } ) . then ( function ( data ) {
839- resolve ( data ) ;
874+ dealWithRet ( data , resolve , reject ) ;
840875 } ) . catch ( function ( err ) {
841- reject ( err , null ) ;
876+ reject ( err ) ;
842877 } ) ;
843878 } )
844879
0 commit comments