32 lines
734 B
JavaScript
32 lines
734 B
JavaScript
import pg from 'pg'
|
|
|
|
/**
|
|
* @typedef {object} User
|
|
* @param {string} name
|
|
* @param {string} passbcrypt
|
|
* @param {number} uidnumber
|
|
* @param {number} id
|
|
* @param {number} disabled
|
|
*/
|
|
|
|
/**
|
|
* @type {pg.Database}
|
|
*/
|
|
export let glauth = undefined
|
|
|
|
export async function dbInit() {
|
|
glauth = new pg.Client({
|
|
host: process.env.PG_HOST ?? 'localhost',
|
|
port: process.env.PG_PORT ?? 5432,
|
|
user: process.env.PG_USER ?? 'glauth',
|
|
password: process.env.PG_PASS ?? 'glauth-password',
|
|
database: process.env.PG_DB ?? 'glauth',
|
|
})
|
|
|
|
return new Promise(
|
|
(resolve, reject) => glauth
|
|
.connect()
|
|
.then(() => resolve())
|
|
.catch(err => reject(err))
|
|
)
|
|
} |