Database Manager

DatabaseManager Class

The most important file of the creation and configuration of the database is in this class (change that was placed in version 2.6).

connectToPostgres(shouldConnect = true) {
    if (shouldConnect && !this.pgPool) {
        this.pgPool = new Pool({
            user: process.env.DATABASEUSER,
            password: process.env.DATABASEPASS,
            host: process.env.DATABASEHOST,
            port: process.env.DATABASEPORT,
            database: process.env.DATABASENAME,
            ssl: {
                rejectUnauthorized: false,
            }
        });
        console.log('Connected to PostgreSQL');
    }
    return this.pgPool;
}

Here we will connect the database using the environment variables that are in env or our server already configured. If the connection was successful it will return true.

On the other hand we will connect supabase to be able to create buckets if necessary.

In this case exactly the same thing happens, it gets the data from the environment variables and connects, if it was successful it returns true.

In case it disconnects postgres starts working:

The connections are then checked for correctness with:

It will return true if connected or false if the connection failed.

Finally this section is in charge of making the queries of the corresponding files in the connection pool, which saves resources since everything is derived by this part and does not have to be used in all the queries manually.

The only thing it requests is that you pass it the query to be performed and the parameters or values to be queried.

Última actualización