   token = parseToken(token)
   return Q.reject(new Error) unless token
 
-  sql = 'DELETE FROM user_reset WHERE user_id=? AND token=?'
+  sql = 'DELETE FROM reset WHERE user_id=? AND token=?'
   query(sql, token)
 
 

# Initialise Nitro database
setup = ->

  log = console.log.bind(console)

  # Create 'user' table
  query("""
    CREATE TABLE IF NOT EXISTS `user` (
     `id`            int(11)        NOT NULL    AUTO_INCREMENT,
     `name`          varchar(100)   NOT NULL,
     `email`         varchar(100)   NOT NULL,
     `password`      char(60)       NOT NULL,
     `pro`           tinyint(1)     NOT NULL,
     `data_task`     mediumblob     NOT NULL,
     `data_list`     mediumblob     NOT NULL,
     `data_pref`     mediumblob     NOT NULL,
     `data_time`     mediumblob     NOT NULL,
     `index_task`    int(11)        NOT NULL    DEFAULT '0',
     `index_list`    int(11)        NOT NULL    DEFAULT '0',
     `created_at`    timestamp      NOT NULL    DEFAULT '0000-00-00 00:00:00',
     `updated_at`    timestamp      NOT NULL    DEFAULT CURRENT_TIMESTAMP       ON UPDATE CURRENT_TIMESTAMP,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
  """).fail(log)

  query("""
    CREATE TABLE IF NOT EXISTS `user_register` (
     `id`         int(11)      NOT NULL  AUTO_INCREMENT,
     `token`      char(22)     NOT NULL,
     `name`       varchar(100) NOT NULL,
     `email`      varchar(100) NOT NULL,
     `password`   char(60)     NOT NULL,
     `created_at` timestamp    NOT NULL  DEFAULT CURRENT_TIMESTAMP,
      PRIMARY KEY (`id`, `token`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
  """).fail(log)

  query("""
    CREATE TABLE IF NOT EXISTS `user_login` (
     `user_id`    int(11)   NOT NULL,
     `token`      char(64)  NOT NULL,
     `created_at` timestamp NOT NULL  DEFAULT CURRENT_TIMESTAMP,
      PRIMARY KEY (`user_id`, `token`),
      FOREIGN KEY (`user_id`) REFERENCES user(`id`) ON DELETE CASCADE
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  """).fail(log)

  query("""
    CREATE TABLE IF NOT EXISTS `user_reset` (
     `user_id`    int(11)      NOT NULL,
     `token`      char(22)     NOT NULL,
     `created_at` timestamp    NOT NULL  DEFAULT CURRENT_TIMESTAMP,
      PRIMARY KEY (`user_id`, `token`),
      FOREIGN KEY (`user_id`) REFERENCES user(`id`) ON DELETE CASCADE
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
  """).fail(log)

close = ->
  db.end()

  return Q.resolve() unless match
  [id, token] = match

  sql = 'SELECT id, name, email, password FROM register WHERE id=? AND token=?'
  query(sql, [id, token]).then (rows) ->
    return unless rows.length
    return rows[0]
