-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabase.ts
34 lines (27 loc) · 885 Bytes
/
database.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// -------------- //
// database logic //
// -------------- //
import { settingsWindow } from './main';
import * as mongodb from "mongodb";
export class Database {
private mongoClient = mongodb.MongoClient;
public constructor() {};
/**
* Checks for successful database connection based on parameters and returns result to renderer
* @param url - DB url
* @param port - DB port
* @param name - DB name
*/
public testConnection(url:String, port:Number, name:String) {
let uri = `mongodb://${url}:${port}/${name}`;
this.mongoClient.connect(uri, {useNewUrlParser: true}, function(err, db) {
if (err) {
console.log('fail');
settingsWindow.webContents.send('test-db-connection', false);
} else {
console.log('success');
settingsWindow.webContents.send('test-db-connection', true);
}
});
};
};