fetch.js 613 B

123456789101112131415161718192021222324252627282930313233343536
  1. function nt() {
  2. var args = Array.prototype.slice.apply(arguments, 1);
  3. var cb = arguments[0];
  4. if(args[args.length-1]) console.log(args[args.length-1]);
  5. if(!cb) console.log("nt called without a function.");
  6. process.nextTick(function() { cb.apply(this, args) });
  7. }
  8. module.exports = function(db) {
  9. var q = 'INSERT INTO `types` (`name`, `'+tcol+'`, `externalType`) VALUES (?, true, ?);';
  10. db.query(q, [name, externalType], function(err, res) {
  11. if(err) {
  12. if(err.code == 'ER_DUP_ENTRY') {
  13. return nt(cb, "type name already exists.");
  14. }
  15. return nt(cb, err);
  16. }
  17. });
  18. };