@ecopex/ecopex-framework 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +8 -3
- package/libraries/knex.js +36 -4
- package/package.json +1 -1
- package/config/database.js +0 -26
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { start: fastifyStart } = require('./libraries/fastify');
|
|
2
|
-
const knex = require('./libraries/knex')
|
|
2
|
+
const knex = require('./libraries/knex')
|
|
3
3
|
const JWT = require('./libraries/jwt');
|
|
4
4
|
const BCRYPT = require('./libraries/bcrypt');
|
|
5
5
|
const date = require('./libraries/date');
|
|
@@ -8,9 +8,14 @@ const twofactor = require('./libraries/2fa');
|
|
|
8
8
|
const jwt = new JWT();
|
|
9
9
|
const bcrypt = new BCRYPT();
|
|
10
10
|
|
|
11
|
+
const start = async (config) => {
|
|
12
|
+
await knex.initialize(config);
|
|
13
|
+
await fastifyStart(config);
|
|
14
|
+
}
|
|
15
|
+
|
|
11
16
|
module.exports = {
|
|
12
|
-
|
|
13
|
-
db: knex,
|
|
17
|
+
start,
|
|
18
|
+
db: knex.instance,
|
|
14
19
|
date: date,
|
|
15
20
|
jwt: jwt,
|
|
16
21
|
bcrypt: bcrypt,
|
package/libraries/knex.js
CHANGED
|
@@ -1,7 +1,39 @@
|
|
|
1
1
|
const knex = require('knex');
|
|
2
|
-
const { config: configStore } = require('../stores/config');
|
|
3
|
-
const config = require('../config/database');
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
let instance = null;
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
const initialize = async (config) => {
|
|
6
|
+
const { config: configStore } = require('../stores/config');
|
|
7
|
+
const databaseConfig = configStore?.database || {};
|
|
8
|
+
|
|
9
|
+
const db_config = {
|
|
10
|
+
development: {
|
|
11
|
+
client: 'mysql2',
|
|
12
|
+
connection: {
|
|
13
|
+
host: databaseConfig.host || 'localhost',
|
|
14
|
+
port: databaseConfig?.port || 3306,
|
|
15
|
+
user: databaseConfig.user || 'root',
|
|
16
|
+
password: databaseConfig?.password || '',
|
|
17
|
+
database: databaseConfig?.database || 'ecopex'
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
production: {
|
|
21
|
+
client: 'mysql2',
|
|
22
|
+
connection: {
|
|
23
|
+
host: databaseConfig?.host || 'localhost',
|
|
24
|
+
port: databaseConfig?.port || 3306,
|
|
25
|
+
user: databaseConfig?.user || 'root',
|
|
26
|
+
password: databaseConfig?.password || '',
|
|
27
|
+
database: databaseConfig?.database || 'ecopex'
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const db = knex(db_config[configStore.development ? 'development' : 'production']);
|
|
33
|
+
instance = db;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = {
|
|
37
|
+
initialize,
|
|
38
|
+
instance
|
|
39
|
+
}
|
package/package.json
CHANGED
package/config/database.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// create knex config for production and development
|
|
2
|
-
const { config: configStore } = require('../stores/config');
|
|
3
|
-
const databaseConfig = configStore?.database || {};
|
|
4
|
-
|
|
5
|
-
module.exports = {
|
|
6
|
-
development: {
|
|
7
|
-
client: 'mysql2',
|
|
8
|
-
connection: {
|
|
9
|
-
host: databaseConfig?.host || 'localhost',
|
|
10
|
-
port: databaseConfig?.port || 3306,
|
|
11
|
-
user: databaseConfig?.user || 'root',
|
|
12
|
-
password: databaseConfig?.password || '',
|
|
13
|
-
database: databaseConfig?.database || 'ecopex'
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
production: {
|
|
17
|
-
client: 'mysql2',
|
|
18
|
-
connection: {
|
|
19
|
-
host: databaseConfig?.host || 'localhost',
|
|
20
|
-
port: databaseConfig?.port || 3306,
|
|
21
|
-
user: databaseConfig?.user || 'root',
|
|
22
|
-
password: databaseConfig?.password || '',
|
|
23
|
-
database: databaseConfig?.database || 'ecopex'
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|