Created
January 24, 2023 10:24
-
-
Save cba85/b6d7a92217e2ac28cfe60c8d2bc03541 to your computer and use it in GitHub Desktop.
Connect MariaDB or JawsDB MariaDB with Heroku and MariaDB node connector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/mariadb-corporation/mariadb-connector-nodejs/blob/master/documentation/connection-options.md | |
require("dotenv").config(); | |
const mariadb = require("mariadb"); | |
(async () => { | |
let conn; | |
if (process.env.APP_ENV == "heroku") { | |
conn = await mariadb.createConnection( | |
`${process.env.JAWSDB_MARIA_URL}?decimalAsNumber=true&bigIntAsNumber=true` | |
); | |
} else { | |
conn = await mariadb.createConnection({ | |
host: process.env.DB_HOST, | |
user: process.env.DB_USER, | |
password: process.env.DB_PASSWORD, | |
database: process.env.DB_DATABASE, | |
decimalAsNumber: true, | |
bigIntAsNumber: true, | |
trace: true, | |
}); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment