feat: Implement PostgreSQL connection

This commit is contained in:
Faruk AYDIN
2021-10-28 15:35:33 +02:00
committed by Ali BARIN
parent 219d24495d
commit 7ed0ec45c3
3 changed files with 228 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
import { Client } from 'pg';
import App from '../../models/app';
export default class PostgreSQL {
client: any
connectionData: any
appData: any
constructor(connectionData: any) {
this.client = new Client({
host: connectionData.host,
port: connectionData.port,
database: connectionData.database,
user: connectionData.username,
password: connectionData.password,
})
this.connectionData = connectionData;
this.appData = App.findOneByKey('postgresql');
}
async verifyCredentials() {
await this.client.connect()
return {
screenName: this.connectionData.database
}
}
async isStillVerified() {
try {
await this.client.connect()
return true;
} catch(error) {
return false
}
}
}