Skip to content

Commit

Permalink
feat(common): APPEX-583 adds mysql8 auth support
Browse files Browse the repository at this point in the history
  • Loading branch information
bc-chaz committed Jul 20, 2023
1 parent f3d0d86 commit a1f5b27
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 166 deletions.
9 changes: 5 additions & 4 deletions lib/dbs/mysql.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import * as mysql from 'mysql';
import { createPool, PoolOptions } from 'mysql2';
import { promisify } from 'util';
import { SessionProps, StoreData } from '../../types';

const MYSQL_CONFIG = {
const MYSQL_CONFIG: PoolOptions = {
host: process.env.MYSQL_HOST,
database: process.env.MYSQL_DATABASE,
user: process.env.MYSQL_USERNAME,
password: process.env.MYSQL_PASSWORD,
...(process.env.MYSQL_PORT && { port: process.env.MYSQL_PORT }),
...(process.env.MYSQL_PORT && { port: Number(process.env.MYSQL_PORT) }),
};

// For use with Heroku ClearDB
// Other mysql: https://www.npmjs.com/package/mysql#pooling-connections
const pool = mysql.createPool(process.env.CLEARDB_DATABASE_URL ? process.env.CLEARDB_DATABASE_URL : MYSQL_CONFIG);
const dbUrl = process.env.CLEARDB_DATABASE_URL;
const pool = dbUrl ? createPool(dbUrl) : createPool(MYSQL_CONFIG);
const query = promisify(pool.query.bind(pool));

// Use setUser for storing global user data (persists between installs)
Expand Down
Loading

0 comments on commit a1f5b27

Please sign in to comment.