database.js 865 B

123456789101112131415161718192021222324
  1. const {Pool} = require('pg');
  2. const db = new Pool();
  3. db.on( 'error', dberror => {
  4. console.log( '- ' + shardId + ': Error while connecting to the database: ' + dberror );
  5. } );
  6. db.query( 'SELECT guild, prefix FROM discord WHERE patreon IS NOT NULL' ).then( ({rows}) => {
  7. console.log( '- ' + shardId + ': Patreons successfully loaded.' );
  8. rows.forEach( row => {
  9. patreons[row.guild] = row.prefix;
  10. } );
  11. }, dberror => {
  12. console.log( '- ' + shardId + ': Error while getting the patreons: ' + dberror );
  13. } );
  14. db.query( 'SELECT guild, lang FROM discord WHERE voice IS NOT NULL' ).then( ({rows}) => {
  15. console.log( '- ' + shardId + ': Voice channels successfully loaded.' );
  16. rows.forEach( row => {
  17. voice[row.guild] = row.lang;
  18. } );
  19. }, dberror => {
  20. console.log( '- ' + shardId + ': Error while getting the voice channels: ' + dberror );
  21. } );
  22. module.exports = db;