multi-db-orm 2.1.6 → 2.1.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.
@@ -19,22 +19,24 @@ declare module 'mysql' {
19
19
  }
20
20
  }
21
21
 
22
+ export type MySQLDBConfig = {
23
+ host: string;
24
+ port: string;
25
+ username: string;
26
+ password: string;
27
+ database: string;
28
+ connectionLimit?: Number;
29
+ connectTimeout?: Number;
30
+ acquireTimeout?: Number;
31
+ timeout?: Number;
32
+ }
33
+
22
34
  export class MySQLDB extends MultiDbORM {
23
35
  db: typeof import('mysql')
24
36
  mysql: typeof import('mysql');
25
37
  connection: import('mysql').Connection;
26
38
 
27
- constructor(credentials: {
28
- host: string;
29
- port: string;
30
- username: string;
31
- password: string;
32
- database: string;
33
- connectionLimit?: Number;
34
- connectTimeout?: Number;
35
- acquireTimeout?: Number;
36
- timeout?: Number;
37
- });
39
+ constructor(credentials: MySQLDBConfig);
38
40
 
39
41
  run(query: string): Promise<any[]>;
40
42
 
@@ -8,6 +8,8 @@ class MySQLDB extends MultiDbORM {
8
8
  dataMap = {
9
9
  "id": "VARCHAR(50) NOT NULL PRIMARY KEY",
10
10
  "string": "VARCHAR(4000)",
11
+ "stringlarge": "TEXT",
12
+ "stringsmall": "VARCHAR(255)",
11
13
  "number": "DOUBLE",
12
14
  "boolean": "BOOL",
13
15
  "array": "TEXT",
@@ -110,7 +112,20 @@ class MySQLDB extends MultiDbORM {
110
112
 
111
113
  var cols = '';
112
114
  for (var key in sampleObject) {
113
- var type = this.dataMap[typeof (sampleObject[key])] || 'TEXT';
115
+ var type;
116
+ if (this.dataMap[sampleObject[key]]) {
117
+ type = this.dataMap[sampleObject[key]]
118
+ } else {
119
+ type = this.dataMap[typeof (sampleObject[key])] || 'TEXT';
120
+ if (typeof (sampleObject[key]) == 'string') {
121
+ if (sampleObject[key].length > 4000) {
122
+ type = this.dataMap['stringlarge']
123
+ }
124
+ if (sampleObject[key].length <= 255) {
125
+ type = this.dataMap['stringsmall']
126
+ }
127
+ }
128
+ }
114
129
  cols = cols + `${key} ${type},`;
115
130
  }
116
131
  cols = cols.substring(0, cols.length - 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "multi-db-orm",
3
- "version": "2.1.6",
3
+ "version": "2.1.8",
4
4
  "description": "CRUD , Backup , Restore and Migration library for multiple databases",
5
5
  "main": "index.js",
6
6
  "dependencies": {
@@ -15,7 +15,7 @@
15
15
  "sqlite3": "^5.0.0"
16
16
  },
17
17
  "scripts": {
18
- "release": "git add -A && git commit -m Update-Files | npm version patch && git add -A && git commit -m Update-Version && git push && npm publish",
18
+ "release": "git add -A && git commit -m Update-Files & npm version patch && git add -A && git commit -m Update-Version & npm publish && git push",
19
19
  "postinstall": "node postinstall.js",
20
20
  "test": "node test/test.js"
21
21
  },