index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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.error('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. playlist: new mongoose.Schema(require(`./schemas/playlist`)),
  17. news: new mongoose.Schema(require(`./schemas/news`)),
  18. reports: new mongoose.Schema(require(`./schemas/reports`))
  19. };
  20. lib.models = {
  21. song: mongoose.model('song', lib.schemas.song),
  22. queueSong: mongoose.model('queueSong', lib.schemas.queueSong),
  23. station: mongoose.model('station', lib.schemas.station),
  24. user: mongoose.model('user', lib.schemas.user),
  25. playlist: mongoose.model('playlist', lib.schemas.playlist),
  26. news: mongoose.model('news', lib.schemas.news),
  27. reports: mongoose.model('reports', lib.schemas.reports)
  28. };
  29. cb();
  30. });
  31. }
  32. };
  33. module.exports = lib;