Skip to content

mssql DataSource testOnBorrow doesn't seem to work #10176

@thisnamewasnottaken

Description

@thisnamewasnottaken

What was unclear or otherwise insufficient?

data-source-options.md defines connection settings for a variety of data sources, among which is MSSQL.

Data Source Option pool.testOnBorrow indicates that factory.validate or factory.validateAsync is required if this field is used.

The Option pool.testOnBorrow appears to fail silently if the required factory.validate or factory.validateAsync isn't provided.

The options factory.validate or factory.validateAsync are not defined anywhere in data-source-options.md

Recommended Fix

Provide a definition for factory.validate or factory.validateAsync in data-source-options.md to clarify the following:

  • Where exactly the option is to be added
  • What is the acceptable value of this (bool?)
  • Perhaps a common example

For instance:

# factory.validate example
export const AppDataSource = new DataSource({
    type: "mssql",
    host: process.env.dbhost,
    port: process.env.dbport,
    pool: {
        max: 10,
        min: 0,
        idleTimeoutMillis: 30000,
        acquireTimeoutMillis: 30000,
        testOnBorrow: true,
    }, 
    factory: {
        validate: async (connection) => {
            try {
                await connection.query("SELECT 1");
            } catch (e) {
                console.error(e);
                return false;
            }
            return true;
        }
    }
})

Additional Context

Google searches, stackoverflow searches, GitHub searches and stackoverflow searches did not help to resolve this issue or give adequate typeorm specific details.

Also noting the typeorm slack channel link is dead.

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, but I don't know how to start. I would need guidance.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions