@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 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
- fastifyStart,
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
- const db = knex(config[configStore.development ? 'development' : 'production']);
3
+ let instance = null;
6
4
 
7
- module.exports = db;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecopex/ecopex-framework",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Javascript Framework for API and Admin Panel",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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
- }