Repository: prisma/prisma
File: packages/adapter-mariadb/src/mariadb.ts (TypeScript)

Code before:

  #capabilities?: Capabilities
  #config: mariadb.PoolConfig | string
  #options?: PrismaMariadbOptions

  constructor(config: mariadb.PoolConfig | string, options?: PrismaMariadbOptions) {
    this.#config = rewriteConnectionString(config)
    this.#options = options
  }

  async connect(): Promise<PrismaMariaDbAdapter> {
    let pool: mariadb.Pool
    try {
      pool = mariadb.createPool(this.#config)
    } catch (error) {
      // We match on an error which is known to leak the connection string and replace it with
      // a custom error message.
      // The error might change in a future version of the driver, but this is covered in a
      // test, which checks for credential leakage regardless of the exact error message.
      if (error instanceof Error && error.message.startsWith('error parsing connection string')) {
        throw new Error(
          "error parsing connection string, format must be 'mariadb://[<user>[:<password>]@]<host>[:<port>]/[<db>[?<opt1>=<value1>[&<opt2>=<value2>]]]'",
        )
      } else {
        throw error
      }
    }
    if (this.#capabilities === undefined) {
      this.#capabilities = await getCapabilities(pool)
    }
    return new PrismaMariaDbAdapter(pool, this.#capabilities, this.#options)
  }
}

async function getCapabilities(pool: mariadb.Pool): Promise<{ supportsRelationJoins: boolean }> {
  const tag = '[js::getCapabilities]'

  try {
    const rows = await pool.query({
      sql: `SELECT VERSION()`,
      rowsAsArray: true,
    })

    const version = rows[0][0]
    debug(`${tag} MySQL version: %s from %o`, version, rows)

    const capabilities = inferCapabilities(version)
    debug(`${tag} Inferred capabilities: %O`, capabilities)

    return capabilities
  } catch (e) {

Review comment (suggestion):
nitpicky


```suggestion
      }
      
      throw error
```

Code after:

  #capabilities?: Capabilities
  #config: mariadb.PoolConfig | string
  #options?: PrismaMariadbOptions

  constructor(config: mariadb.PoolConfig | string, options?: PrismaMariadbOptions) {
    this.#config = rewriteConnectionString(config)
    this.#options = options
  }

  async connect(): Promise<PrismaMariaDbAdapter> {
    let pool: mariadb.Pool
    try {
      pool = mariadb.createPool(this.#config)
    } catch (error) {
      // We match on an error which is known to leak the connection string and replace it with
      // a custom error message.
      // The error might change in a future version of the driver, but this is covered in a
      // test, which checks for credential leakage regardless of the exact error message.
      if (error instanceof Error && error.message.startsWith('error parsing connection string')) {
        throw new Error(
          "error parsing connection string, format must be 'mariadb://[<user>[:<password>]@]<host>[:<port>]/[<db>[?<opt1>=<value1>[&<opt2>=<value2>]]]'",
        )
      }
      throw error
    }
    if (this.#capabilities === undefined) {
      this.#capabilities = await getCapabilities(pool)
    }
    return new PrismaMariaDbAdapter(pool, this.#capabilities, this.#options)
  }
}

async function getCapabilities(pool: mariadb.Pool): Promise<{ supportsRelationJoins: boolean }> {
  const tag = '[js::getCapabilities]'

  try {
    const rows = await pool.query({
      sql: `SELECT VERSION()`,
      rowsAsArray: true,
    })

    const version = rows[0][0]
    debug(`${tag} MySQL version: %s from %o`, version, rows)

    const capabilities = inferCapabilities(version)
    debug(`${tag} Inferred capabilities: %O`, capabilities)

    return capabilities
  } catch (e) {
    debug(`${tag} Error while checking capabilities: %O`, e)