Skip to content

Cannot specify database when using an existing connection pool #146

@RedSpid3r

Description

@RedSpid3r

I am trying to using my existing connection pool with express-mysql-session, however, in doing so i am unable to specify the database name.

My app connected to multiple databases which is why I am not setting database name in mysql2 createPool options.

	const sessionStore = new MySQLStore({ database: "db_name" }, pool);
	app.use(
		session({
			key: `APP_${process.env.NODE_ENV}`,
			secret: process.env.SESSION_SECRET,
			store: sessionStore,
			resave: false,
			saveUninitialized: false,
			clearExpired: true,
			checkExpirationInterval: 900000,
			cookie: {
				secure: process.env.NODE_ENV === "production" ? true : false,
				maxAge: 2629800000,
			},
		})
	);

this results in:

  code: 'ER_NO_DB_ERROR',
  errno: 1046,
  sql: "SELECT `data` AS data, `expires` as expires FROM `sessions` WHERE `session_id` = '[REDACTED]'",
  sqlState: '3D000',
  sqlMessage: 'No database selected'

Is there a way to make this work or do i need to keep using 2 separate connection pools?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions