const { exec } = require ( 'child_process' ) ; const { dialog } = require ( 'electron' ) ; interface CreateSQLQuery { ( string ) : string ; } interface CreateCommand { ( dbName , file ) : string ; } interface HelperFunctions { createDBFunc : CreateSQLQuery ; dropDBFunc : CreateSQLQuery ; explainQuery : CreateSQLQuery ; runSQLFunc : CreateCommand ; runTARFunc : CreateCommand ; runFullCopyFunc : CreateCommand ; runHollowCopyFunc : CreateCommand ; promExecute : ( cmd : string ) => Promise < { stdout : string ; stderr : string ; } > ; } const helperFunctions = { createDBFunc : ( name ) => `CREATE DATABASE "${ name }"` , dropDBFunc : ( dbName ) => `DROP DATABASE "${ dbName }"` , explainQuery : ( sqlString ) => `BEGIN; EXPLAIN (FORMAT JSON, ANALYZE, VERBOSE, BUFFERS) ${ sqlString }; ROLLBACK;` , runSQLFunc : ( dbName , file ) => `psql -U postgres -d ${ dbName } -f "${ file }"` , runTARFunc : ( dbName , file ) => `pg_restore -U postgres -d ${ dbName } "${ file }"` , runFullCopyFunc : ( dbCopyName , newFile ) => `pg_dump -U postgres -F p -d ${ dbCopyName } > "${ newFile }"` , runHollowCopyFunc : ( dbCopyName , file ) => `pg_dump -s -U postgres -F p -d ${ dbCopyName } > "${ file }"` , promExecute : ( cmd ) => new Promise ( ( resolve , reject ) => { exec ( cmd , ( error , stdout , stderr ) => { if ( error ) return reject ( error ) ; if ( stderr ) return reject ( new Error ( stderr ) ) ; return resolve ( { stdout , stderr } ) ; } ) ; } ) , } ; export default helperFunctions ;