qwik-account-manager/libs/database.js

32 lines
734 B
JavaScript
Raw Normal View History

2022-01-23 15:52:12 +01:00
import pg from 'pg'
2022-01-15 19:27:18 +01:00
2022-01-22 21:32:14 +01:00
/**
* @typedef {object} User
* @param {string} name
* @param {string} passbcrypt
* @param {number} uidnumber
* @param {number} id
* @param {number} disabled
*/
/**
2022-01-23 15:52:12 +01:00
* @type {pg.Database}
2022-01-22 21:32:14 +01:00
*/
2022-01-15 19:27:18 +01:00
export let glauth = undefined
2022-01-23 15:52:12 +01:00
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',
})
2022-01-15 19:27:18 +01:00
2022-01-23 15:52:12 +01:00
return new Promise(
(resolve, reject) => glauth
.connect()
.then(() => resolve())
.catch(err => reject(err))
)
2022-01-15 19:27:18 +01:00
}