index.js 887 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. const mongoose = require('mongoose');
  3. let lib = {
  4. connection: null,
  5. schemas: {},
  6. models: {},
  7. init: (url, cb) => {
  8. lib.connection = mongoose.connect(url).connection;
  9. lib.connection.on('error', err => console.log('Database error: ' + err.message));
  10. lib.connection.once('open', _ => {
  11. lib.schemas = {
  12. song: new mongoose.Schema(require(`./schemas/song`)),
  13. queueSong: new mongoose.Schema(require(`./schemas/queueSong`)),
  14. station: new mongoose.Schema(require(`./schemas/station`)),
  15. user: new mongoose.Schema(require(`./schemas/user`))
  16. };
  17. lib.models = {
  18. song: mongoose.model('song', lib.schemas.song),
  19. queueSong: mongoose.model('queueSong', lib.schemas.queueSong),
  20. station: mongoose.model('station', lib.schemas.station),
  21. user: mongoose.model('user', lib.schemas.user)
  22. };
  23. cb();
  24. });
  25. }
  26. };
  27. module.exports = lib;