Express Sweet API Reference - v3.0.0
    Preparing search index...

    Class DatabaseManager

    Database manager class for handling Sequelize database connections. Implements singleton pattern to ensure single database connection across the application.

    // Get database instance
    const db = await DatabaseManager.getInstance();

    // Check connection
    const isConnected = await DatabaseManager.isConnected();

    // Get configuration
    const config = await DatabaseManager.getConfig();
    Index

    Constructors

    Methods

    • Gets the singleton Sequelize database instance. Creates a new instance on first call, returns cached instance on subsequent calls.

      Returns Promise<Sequelize>

      The Sequelize database instance

      When database configuration loading fails

      const sequelize = await DatabaseManager.getInstance();
      const users = await sequelize.models.User.findAll();
    • Tests the database connection.

      Returns Promise<boolean>

      Returns true if connection is successful, false otherwise

      const canConnect = await DatabaseManager.isConnected();
      if (canConnect) {
      console.log('Database is accessible');
      } else {
      console.error('Cannot connect to database');
      }
    • Gets the original database configuration loaded from config files. This returns the raw configuration before Sequelize processing.

      Returns Promise<object>

      Database configuration object containing all loaded options

      When configuration loading fails

      const config = await DatabaseManager.getConfig();
      console.log('Database name:', config.database);
      console.log('Host:', config.host);
      console.log('Port:', config.port);
    • Gets the runtime Sequelize options after initialization. This returns the actual options used by the Sequelize instance, which may include defaults and processed values.

      Returns Promise<object>

      Sequelize runtime options object

      const options = await DatabaseManager.getSequelizeOptions();
      console.log('Connection pool settings:', options.pool);
      console.log('Dialect:', options.dialect);
    • Closes the database connection and resets the singleton instance. Useful for testing or graceful application shutdown.

      Returns Promise<void>

      // Graceful shutdown
      process.on('SIGTERM', async () => {
      await DatabaseManager.close();
      process.exit(0);
      });