app.js
/**
 * load_database
 * 
 * Update database with contents of subs.txt
 */


Update database with contents of subs.txt
Update database with contents of subs . txt
function load_database() {
  return new Promise((resolve, reject) => {
    var comment = /^\s*#/
    var stmt = DB.prepare("INSERT INTO subs (name) VALUES (?)");
    var list = readline.createInterface({
      input: fs.createReadStream(path.join(__dirname, 'subs.txt'))
    });
    list.on('line', (line) => {
      if (comment.test(line) || ! line.trim()) return;
      stmt.run(line.trim(), (err) => {
        if (err && ! err.message.startsWith('SQLITE_CONSTRAINT: UNIQUE')) {
          throw err;
        }
      });
    });
    list.on('close', () => {
      stmt.finalize();
      resolve();
    });
  });
}
function load_database ( ) { return new Promise ( ( resolve , reject ) => { var comment = / ^\s*# / var stmt = DB . prepare ( "INSERT INTO subs (name) VALUES (?)" ) ; var list = readline . createInterface ( { input : fs . createReadStream ( path . join ( __dirname , 'subs.txt' ) ) } ) ; list . on ( 'line' , ( line ) => { if ( comment . test ( line ) || ! line . trim ( ) ) return ; stmt . run ( line . trim ( ) , ( err ) => { if ( err && ! err . message . startsWith ( 'SQLITE_CONSTRAINT: UNIQUE' ) ) { throw err ; } } ) ; } ) ; list . on ( 'close' , ( ) => { stmt . finalize ( ) ; resolve ( ) ; } ) ; } ) ; }
load_database
load_database