daily pastebin goal
38%
SHARE
TWEET

Untitled

a guest Dec 18th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var mongoose = require('mongoose');
  2.  
  3. /**
  4.  * Models
  5.  */
  6.  
  7. var SettingsScheme = mongoose.Schema({
  8.   key: String,
  9.   value: mongoose.Schema.Types.Mixed
  10. });
  11.  
  12. SettingsScheme.statics.get = function (key, cb) {
  13.   this.findOne({key: key}, 'value', function (err, record) {
  14.     if (record !== null) {
  15.       record = record.value;
  16.     }
  17.     cb(err, record);
  18.   });
  19. };
  20.  
  21. SettingsScheme.statics.set = function (key, value, cb) {
  22.   this.findOne({key: key}, function (err, object) {
  23.     if (object === null) {
  24.       object = new Settings({
  25.         key: key
  26.       });
  27.     }
  28.     object.value = value;
  29.     object.save(cb);
  30.   });
  31. };
  32.  
  33.  
  34. /**
  35.  * Init models
  36.  */
  37. var Settings = mongoose.model('Settings', SettingsScheme);
  38.  
  39. /**
  40.  * Globals
  41.  */
  42. module.exports = Settings;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top