@@ -390,6 +390,45 @@ ChainsqlAPI.prototype.dropTable = function (name) {
390390 return this ;
391391 }
392392}
393+
394+ ChainsqlAPI . prototype . addTableFields = function ( name , raw ) {
395+ validate . create ( name , raw ) ;
396+ return modifyTable ( this , opType . t_add_fields , name , raw ) ;
397+ }
398+
399+ ChainsqlAPI . prototype . deleteTableFields = function ( name , raw ) {
400+ return modifyTable ( this , opType . t_delete_fields , name , raw ) ;
401+ }
402+
403+ ChainsqlAPI . prototype . modifyTableFields = function ( name , raw ) {
404+ validate . create ( name , raw ) ;
405+ return modifyTable ( this , opType . t_modify_fields , name , raw ) ;
406+ }
407+
408+ ChainsqlAPI . prototype . createIndex = function ( name , raw ) {
409+ return modifyTable ( this , opType . t_create_index , name , raw ) ;
410+ }
411+
412+ ChainsqlAPI . prototype . deleteIndex = function ( name , raw ) {
413+ return modifyTable ( this , opType . t_delete_index , name , raw ) ;
414+ }
415+
416+ function modifyTable ( ChainSQL , optype , name , raw ) {
417+ ChainSQL . payment = {
418+ address : ChainSQL . connect . address ,
419+ opType : optype ,
420+ tables : [ {
421+ Table : {
422+ TableName : convertStringToHex ( name )
423+ }
424+ } ] ,
425+ raw : JSON . stringify ( raw ) ,
426+ tsType : 'TableListSet' ,
427+ } ;
428+
429+ return ChainSQL ;
430+ }
431+
393432ChainsqlAPI . prototype . renameTable = function ( oldName , newName ) {
394433 if ( newName == '' || ! newName ) {
395434 throw chainsqlError ( "Table new name can not be empty" )
@@ -1068,15 +1107,23 @@ ChainsqlAPI.prototype.prepareJson = function(){
10681107 reject ( error )
10691108 } ) ;
10701109
1071- }
1072- else if ( that . payment . opType === opType [ 't_grant' ] ) {
1073- handleGrantPayment ( that ) . then ( ( ) => {
1110+ } else {
1111+ if ( that . payment . opType === opType [ 't_grant' ] ) {
1112+ handleGrantPayment ( that ) . then ( ( ) => {
1113+ that . api . prepareTable ( that , that . payment , resolve , reject ) ;
1114+ } ) . catch ( error => {
1115+ reject ( error ) ;
1116+ } ) ;
1117+ } else if ( that . payment . opType >= opType . t_add_fields && that . payment . opType <= opType . t_delete_index ) {
1118+ util . tryEncryptRaw ( that , that . payment ) . then ( function ( raw ) {
1119+ that . payment . raw = raw ;
1120+ that . api . prepareTable ( that , that . payment , resolve , reject ) ;
1121+ } ) . catch ( function ( error ) {
1122+ reject ( error ) ;
1123+ } ) ;
1124+ } else {
10741125 that . api . prepareTable ( that , that . payment , resolve , reject ) ;
1075- } ) . catch ( error => {
1076- reject ( error ) ;
1077- } ) ;
1078- } else {
1079- that . api . prepareTable ( that , that . payment , resolve , reject ) ;
1126+ }
10801127 }
10811128 } )
10821129}
0 commit comments