Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using MariaDB pool #137

Open
ITSNOTSTUPIDIFITWORKS opened this issue May 27, 2022 · 6 comments
Open

Error when using MariaDB pool #137

ITSNOTSTUPIDIFITWORKS opened this issue May 27, 2022 · 6 comments

Comments

@ITSNOTSTUPIDIFITWORKS
Copy link

ITSNOTSTUPIDIFITWORKS commented May 27, 2022

Hi!

Without a pool everything works fine.

If I try to use a pool:

const mariadb = require("mariadb");

const pool = mariadb.createPool({
  database: process.env.SQL_DB,
  host: process.env.SQL_HOST,
  user: process.env.SQL_USER,
  password: process.env.SQL_PASSWORD,
  connectionLimit: 10,
});

I get the following error:

text: 'Parameter at position 6 is not set',
  sql: "SELECT ?? AS data, ?? as expires FROM ?? WHERE ?? = ? - parameters:['data','expires','sessions','session_id','xD3hu_1EuRI6JOX1wMztKoLFkuK2QPse']",

Can someone help?

@ARR4NN
Copy link

ARR4NN commented Aug 25, 2022

I am having the same issue. Did you find a fix for this? Much appreciated

@YasserB94
Copy link

Bump!

@InanisOmnia
Copy link

Same issue, any solutions as of yet?

@YasserB94
Copy link

YasserB94 commented Jan 8, 2023

Same issue, any solutions as of yet?

Hi the LordFarquhar,
I have not used this in a while, but eventually following code worked for us to query the database.

const mariadb = require("mariadb");

const pool = mariadb.createPool({
  host: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
  connectionLimit: 5,
});
//Check for common errors
pool.getConnection((error, connection) => {
    if (error) {
        switch (error.code) {
            case "PROTOCOL_CONNECTION_LOST":
                console.error("DB CONNECTION LOST!");
                break;
            case "ER_CON_COUNT_ERROR":
                console.error("DB RECEIVED TOO MANY CONNECTIONS");
                break;
            case "ECONNREFUSED":
                console.error("DB HAS REFUSED CONNECTION");
                break;
            case "ER_GET_CONNECTION_TIMEOUT":
                console.error("NO CONNECTION TO DATABASE");
                console.error("MAKE SURE YOU HAVE A REACHABLE MARIADB DATABASE");
                console.error(
                    "CHECK YOUR .ENV FILE AND TEST YOUR CONNECTION WITH GIVEN CREDENTIALS"
                );
                break;
        }
    }
    if (connection) {
        connection.release();
    }
});
module.exports = pool;

Example of a class that uses queries:

const pool = require("../helpers/database");
class User {
  constructor() {
    this.pool = pool;
  }
  async getUserByEmail(email) {
    const query =
      "SELECT id,name,email,image_url FROM user_table WHERE email LIKE ?";
    return this.pool.query(query, email);
  }
}

@chill117
Copy link
Owner

chill117 commented Mar 16, 2023

MariaDB is not explicitly supported by this module, but might work if your version of MariaDB is compatible with MySQL 5.7. Please try to use the latest version of this module (v3) - there were recent changes that might improve compatibility.

@chill117
Copy link
Owner

I tested the latest version of this module with the latest MariaDB (10.7.8). All tests are passing - so it should be safe to use this module with MariaDB. But it's important to note that this module is not compatible with the mariadb nodejs module that was referenced above in this issue. You should follow the usage examples as shown in this module's readme here or here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants