types / mysql2

Typings for https://github.com/sidorares/node-mysql2
ISC License
41 stars 23 forks source link

Missing Pool Promise #41

Open aollag09 opened 4 years ago

aollag09 commented 4 years ago

Hi there,

The function promise() is not available on the Pool class :( !? Thanks for your help !

OssiPesonen commented 2 years ago

Tad late to the party here, but here's how I solved my types.

import * as mysql from 'mysql2';
import { Connection, Pool } from 'mysql2';

export const createConnectionPool = (): Pool => {
  return mysql.createPool(databaseConfig);
}

// When called I cast it as Connection because Pool extends it
const pool = config.createConnectionPool() as Connection;
const db = pool.promise();

Now the Connection type for db is from mysql2/promise