-
Notifications
You must be signed in to change notification settings - Fork 1
/
database.ts
40 lines (33 loc) · 1.04 KB
/
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
35
36
37
38
39
40
import * as Bookshelf from 'bookshelf';
import * as Knex from 'knex';
import config from './config/main.js';
/**
* Represents the connection of the database using bookshelf.
* Using the Singleton Design Pattern to make just one instance for the connection.
* @name Database
* @class
* @author Roliver Javier Rodriguez
*/
export class Database {
private static database: Database;
private bookshelf: Bookshelf;
private constructor() {
var knex = Knex({
client: config.database.dialect,
connection: {
host: config.database.host,
user: config.database.user,
password: config.database.password,
database: config.database.database,
charset: config.database.sharset
}
});
this.bookshelf = new Bookshelf(knex);
}
public static getInstance(): Database {
return this.database || (this.database = new this());
}
public getConnection = function () {
return this.bookshelf;
}
};