knex 0.21.20 → 0.21.21

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.
Files changed (141) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/CONTRIBUTING.md +184 -184
  3. package/LICENSE +22 -22
  4. package/README.md +95 -95
  5. package/bin/cli.js +414 -414
  6. package/bin/utils/cli-config-utils.js +151 -151
  7. package/bin/utils/constants.js +7 -7
  8. package/bin/utils/migrationsLister.js +37 -37
  9. package/knex.js +8 -8
  10. package/lib/client.js +413 -413
  11. package/lib/config-resolver.js +61 -61
  12. package/lib/constants.js +44 -44
  13. package/lib/dialects/mssql/index.js +390 -390
  14. package/lib/dialects/mssql/query/compiler.js +444 -444
  15. package/lib/dialects/mssql/schema/columncompiler.js +103 -103
  16. package/lib/dialects/mssql/schema/compiler.js +59 -59
  17. package/lib/dialects/mssql/schema/tablecompiler.js +245 -245
  18. package/lib/dialects/mssql/transaction.js +97 -97
  19. package/lib/dialects/mysql/index.js +191 -191
  20. package/lib/dialects/mysql/query/compiler.js +142 -142
  21. package/lib/dialects/mysql/schema/columncompiler.js +171 -171
  22. package/lib/dialects/mysql/schema/compiler.js +60 -60
  23. package/lib/dialects/mysql/schema/tablecompiler.js +262 -262
  24. package/lib/dialects/mysql/transaction.js +48 -48
  25. package/lib/dialects/mysql2/index.js +35 -35
  26. package/lib/dialects/mysql2/transaction.js +46 -46
  27. package/lib/dialects/oracle/DEAD_CODE.md +5 -5
  28. package/lib/dialects/oracle/formatter.js +20 -20
  29. package/lib/dialects/oracle/index.js +79 -79
  30. package/lib/dialects/oracle/query/compiler.js +327 -327
  31. package/lib/dialects/oracle/schema/columnbuilder.js +18 -18
  32. package/lib/dialects/oracle/schema/columncompiler.js +139 -139
  33. package/lib/dialects/oracle/schema/compiler.js +81 -81
  34. package/lib/dialects/oracle/schema/tablecompiler.js +165 -165
  35. package/lib/dialects/oracle/schema/trigger.js +126 -126
  36. package/lib/dialects/oracle/utils.js +86 -86
  37. package/lib/dialects/oracledb/index.js +489 -489
  38. package/lib/dialects/oracledb/query/compiler.js +363 -363
  39. package/lib/dialects/oracledb/schema/columncompiler.js +35 -35
  40. package/lib/dialects/oracledb/transaction.js +76 -76
  41. package/lib/dialects/oracledb/utils.js +14 -14
  42. package/lib/dialects/postgres/index.js +319 -319
  43. package/lib/dialects/postgres/query/compiler.js +206 -206
  44. package/lib/dialects/postgres/schema/columncompiler.js +125 -125
  45. package/lib/dialects/postgres/schema/compiler.js +109 -109
  46. package/lib/dialects/postgres/schema/tablecompiler.js +183 -183
  47. package/lib/dialects/redshift/index.js +73 -73
  48. package/lib/dialects/redshift/query/compiler.js +119 -119
  49. package/lib/dialects/redshift/schema/columnbuilder.js +20 -20
  50. package/lib/dialects/redshift/schema/columncompiler.js +60 -60
  51. package/lib/dialects/redshift/schema/compiler.js +14 -14
  52. package/lib/dialects/redshift/schema/tablecompiler.js +123 -123
  53. package/lib/dialects/redshift/transaction.js +18 -18
  54. package/lib/dialects/sqlite3/formatter.js +21 -21
  55. package/lib/dialects/sqlite3/index.js +169 -169
  56. package/lib/dialects/sqlite3/query/compiler.js +222 -222
  57. package/lib/dialects/sqlite3/schema/columncompiler.js +27 -27
  58. package/lib/dialects/sqlite3/schema/compiler.js +49 -49
  59. package/lib/dialects/sqlite3/schema/ddl.js +525 -525
  60. package/lib/dialects/sqlite3/schema/tablecompiler.js +238 -238
  61. package/lib/formatter.js +295 -295
  62. package/lib/functionhelper.js +14 -14
  63. package/lib/helpers.js +92 -92
  64. package/lib/index.js +3 -3
  65. package/lib/interface.js +115 -115
  66. package/lib/knex.js +42 -42
  67. package/lib/logger.js +76 -76
  68. package/lib/migrate/MigrationGenerator.js +82 -82
  69. package/lib/migrate/Migrator.js +611 -611
  70. package/lib/migrate/configuration-merger.js +60 -60
  71. package/lib/migrate/migrate-stub.js +17 -17
  72. package/lib/migrate/migration-list-resolver.js +36 -36
  73. package/lib/migrate/sources/fs-migrations.js +99 -99
  74. package/lib/migrate/stub/cjs.stub +15 -15
  75. package/lib/migrate/stub/coffee.stub +13 -13
  76. package/lib/migrate/stub/eg.stub +14 -14
  77. package/lib/migrate/stub/js.stub +15 -15
  78. package/lib/migrate/stub/knexfile-coffee.stub +34 -34
  79. package/lib/migrate/stub/knexfile-eg.stub +43 -43
  80. package/lib/migrate/stub/knexfile-js.stub +44 -44
  81. package/lib/migrate/stub/knexfile-ls.stub +35 -35
  82. package/lib/migrate/stub/knexfile-ts.stub +44 -44
  83. package/lib/migrate/stub/ls.stub +14 -14
  84. package/lib/migrate/stub/ts.stub +21 -21
  85. package/lib/migrate/table-creator.js +67 -67
  86. package/lib/migrate/table-resolver.js +27 -27
  87. package/lib/query/builder.js +1372 -1372
  88. package/lib/query/compiler.js +889 -889
  89. package/lib/query/constants.js +13 -13
  90. package/lib/query/joinclause.js +263 -263
  91. package/lib/query/methods.js +92 -92
  92. package/lib/query/string.js +190 -190
  93. package/lib/raw.js +188 -188
  94. package/lib/ref.js +39 -39
  95. package/lib/runner.js +285 -285
  96. package/lib/schema/builder.js +82 -82
  97. package/lib/schema/columnbuilder.js +117 -117
  98. package/lib/schema/columncompiler.js +177 -177
  99. package/lib/schema/compiler.js +101 -101
  100. package/lib/schema/helpers.js +51 -51
  101. package/lib/schema/tablebuilder.js +288 -288
  102. package/lib/schema/tablecompiler.js +296 -296
  103. package/lib/seed/Seeder.js +203 -203
  104. package/lib/seed/seed-stub.js +13 -13
  105. package/lib/seed/stub/coffee.stub +9 -9
  106. package/lib/seed/stub/eg.stub +11 -11
  107. package/lib/seed/stub/js.stub +13 -13
  108. package/lib/seed/stub/ls.stub +11 -11
  109. package/lib/seed/stub/ts.stub +13 -13
  110. package/lib/transaction.js +363 -363
  111. package/lib/util/batchInsert.js +59 -59
  112. package/lib/util/delay.js +6 -6
  113. package/lib/util/fake-client.js +9 -9
  114. package/lib/util/finally-mixin.js +13 -13
  115. package/lib/util/fs.js +76 -76
  116. package/lib/util/import-file.js +13 -13
  117. package/lib/util/is-module-type.js +14 -14
  118. package/lib/util/is.js +32 -32
  119. package/lib/util/make-knex.js +338 -338
  120. package/lib/util/nanoid.js +29 -29
  121. package/lib/util/noop.js +1 -1
  122. package/lib/util/parse-connection.js +66 -66
  123. package/lib/util/save-async-stack.js +14 -14
  124. package/lib/util/template.js +52 -52
  125. package/lib/util/timeout.js +29 -29
  126. package/lib/util/timestamp.js +16 -16
  127. package/package.json +1 -1
  128. package/scripts/build.js +125 -125
  129. package/scripts/docker-compose.yml +111 -111
  130. package/scripts/next-release-howto.md +24 -24
  131. package/scripts/release.sh +34 -34
  132. package/scripts/runkit-example.js +34 -34
  133. package/scripts/stress-test/README.txt +18 -18
  134. package/scripts/stress-test/docker-compose.yml +47 -47
  135. package/scripts/stress-test/knex-stress-test.js +196 -196
  136. package/scripts/stress-test/mysql2-random-hanging-every-now-and-then.js +145 -145
  137. package/scripts/stress-test/mysql2-sudden-exit-without-error.js +100 -100
  138. package/scripts/stress-test/reconnect-test-mysql-based-drivers.js +184 -184
  139. package/types/index.d.ts +2249 -2249
  140. package/types/result.d.ts +27 -27
  141. package/types/tables.d.ts +4 -4
@@ -1,92 +1,92 @@
1
- // All properties we can use to start a query chain
2
- // from the `knex` object, e.g. `knex.select('*').from(...`
3
- module.exports = [
4
- 'with',
5
- 'withRecursive',
6
- 'select',
7
- 'as',
8
- 'columns',
9
- 'column',
10
- 'from',
11
- 'fromJS',
12
- 'into',
13
- 'withSchema',
14
- 'table',
15
- 'distinct',
16
- 'join',
17
- 'joinRaw',
18
- 'innerJoin',
19
- 'leftJoin',
20
- 'leftOuterJoin',
21
- 'rightJoin',
22
- 'rightOuterJoin',
23
- 'outerJoin',
24
- 'fullOuterJoin',
25
- 'crossJoin',
26
- 'where',
27
- 'andWhere',
28
- 'orWhere',
29
- 'whereNot',
30
- 'orWhereNot',
31
- 'whereRaw',
32
- 'whereWrapped',
33
- 'havingWrapped',
34
- 'orWhereRaw',
35
- 'whereExists',
36
- 'orWhereExists',
37
- 'whereNotExists',
38
- 'orWhereNotExists',
39
- 'whereIn',
40
- 'orWhereIn',
41
- 'whereNotIn',
42
- 'orWhereNotIn',
43
- 'whereNull',
44
- 'orWhereNull',
45
- 'whereNotNull',
46
- 'orWhereNotNull',
47
- 'whereBetween',
48
- 'whereNotBetween',
49
- 'andWhereBetween',
50
- 'andWhereNotBetween',
51
- 'orWhereBetween',
52
- 'orWhereNotBetween',
53
- 'groupBy',
54
- 'groupByRaw',
55
- 'orderBy',
56
- 'orderByRaw',
57
- 'union',
58
- 'unionAll',
59
- 'intersect',
60
- 'having',
61
- 'havingRaw',
62
- 'orHaving',
63
- 'orHavingRaw',
64
- 'offset',
65
- 'limit',
66
- 'count',
67
- 'countDistinct',
68
- 'min',
69
- 'max',
70
- 'sum',
71
- 'sumDistinct',
72
- 'avg',
73
- 'avgDistinct',
74
- 'increment',
75
- 'decrement',
76
- 'first',
77
- 'debug',
78
- 'pluck',
79
- 'clearSelect',
80
- 'clearWhere',
81
- 'clearGroup',
82
- 'clearOrder',
83
- 'clearHaving',
84
- 'insert',
85
- 'update',
86
- 'returning',
87
- 'del',
88
- 'delete',
89
- 'truncate',
90
- 'transacting',
91
- 'connection',
92
- ];
1
+ // All properties we can use to start a query chain
2
+ // from the `knex` object, e.g. `knex.select('*').from(...`
3
+ module.exports = [
4
+ 'with',
5
+ 'withRecursive',
6
+ 'select',
7
+ 'as',
8
+ 'columns',
9
+ 'column',
10
+ 'from',
11
+ 'fromJS',
12
+ 'into',
13
+ 'withSchema',
14
+ 'table',
15
+ 'distinct',
16
+ 'join',
17
+ 'joinRaw',
18
+ 'innerJoin',
19
+ 'leftJoin',
20
+ 'leftOuterJoin',
21
+ 'rightJoin',
22
+ 'rightOuterJoin',
23
+ 'outerJoin',
24
+ 'fullOuterJoin',
25
+ 'crossJoin',
26
+ 'where',
27
+ 'andWhere',
28
+ 'orWhere',
29
+ 'whereNot',
30
+ 'orWhereNot',
31
+ 'whereRaw',
32
+ 'whereWrapped',
33
+ 'havingWrapped',
34
+ 'orWhereRaw',
35
+ 'whereExists',
36
+ 'orWhereExists',
37
+ 'whereNotExists',
38
+ 'orWhereNotExists',
39
+ 'whereIn',
40
+ 'orWhereIn',
41
+ 'whereNotIn',
42
+ 'orWhereNotIn',
43
+ 'whereNull',
44
+ 'orWhereNull',
45
+ 'whereNotNull',
46
+ 'orWhereNotNull',
47
+ 'whereBetween',
48
+ 'whereNotBetween',
49
+ 'andWhereBetween',
50
+ 'andWhereNotBetween',
51
+ 'orWhereBetween',
52
+ 'orWhereNotBetween',
53
+ 'groupBy',
54
+ 'groupByRaw',
55
+ 'orderBy',
56
+ 'orderByRaw',
57
+ 'union',
58
+ 'unionAll',
59
+ 'intersect',
60
+ 'having',
61
+ 'havingRaw',
62
+ 'orHaving',
63
+ 'orHavingRaw',
64
+ 'offset',
65
+ 'limit',
66
+ 'count',
67
+ 'countDistinct',
68
+ 'min',
69
+ 'max',
70
+ 'sum',
71
+ 'sumDistinct',
72
+ 'avg',
73
+ 'avgDistinct',
74
+ 'increment',
75
+ 'decrement',
76
+ 'first',
77
+ 'debug',
78
+ 'pluck',
79
+ 'clearSelect',
80
+ 'clearWhere',
81
+ 'clearGroup',
82
+ 'clearOrder',
83
+ 'clearHaving',
84
+ 'insert',
85
+ 'update',
86
+ 'returning',
87
+ 'del',
88
+ 'delete',
89
+ 'truncate',
90
+ 'transacting',
91
+ 'connection',
92
+ ];
@@ -1,190 +1,190 @@
1
- /*eslint max-len: 0, no-var:0 */
2
-
3
- const charsRegex = /[\0\b\t\n\r\x1a"'\\]/g; // eslint-disable-line no-control-regex
4
- const charsMap = {
5
- '\0': '\\0',
6
- '\b': '\\b',
7
- '\t': '\\t',
8
- '\n': '\\n',
9
- '\r': '\\r',
10
- '\x1a': '\\Z',
11
- '"': '\\"',
12
- "'": "\\'",
13
- '\\': '\\\\',
14
- };
15
-
16
- function wrapEscape(escapeFn) {
17
- return function finalEscape(val, ctx = {}) {
18
- return escapeFn(val, finalEscape, ctx);
19
- };
20
- }
21
-
22
- function makeEscape(config = {}) {
23
- const finalEscapeDate = config.escapeDate || dateToString;
24
- const finalEscapeArray = config.escapeArray || arrayToList;
25
- const finalEscapeBuffer = config.escapeBuffer || bufferToString;
26
- const finalEscapeString = config.escapeString || escapeString;
27
- const finalEscapeObject = config.escapeObject || escapeObject;
28
- const finalWrap = config.wrap || wrapEscape;
29
-
30
- function escapeFn(val, finalEscape, ctx) {
31
- if (val === undefined || val === null) {
32
- return 'NULL';
33
- }
34
- switch (typeof val) {
35
- case 'boolean':
36
- return val ? 'true' : 'false';
37
- case 'number':
38
- return val + '';
39
- case 'object':
40
- if (val instanceof Date) {
41
- val = finalEscapeDate(val, finalEscape, ctx);
42
- } else if (Array.isArray(val)) {
43
- return finalEscapeArray(val, finalEscape, ctx);
44
- } else if (Buffer.isBuffer(val)) {
45
- return finalEscapeBuffer(val, finalEscape, ctx);
46
- } else {
47
- return finalEscapeObject(val, finalEscape, ctx);
48
- }
49
- }
50
- return finalEscapeString(val, finalEscape, ctx);
51
- }
52
-
53
- return finalWrap ? finalWrap(escapeFn) : escapeFn;
54
- }
55
-
56
- function escapeObject(val, finalEscape, ctx) {
57
- if (val && typeof val.toSQL === 'function') {
58
- return val.toSQL(ctx);
59
- } else {
60
- return JSON.stringify(val);
61
- }
62
- }
63
-
64
- function arrayToList(array, finalEscape, ctx) {
65
- let sql = '';
66
- for (let i = 0; i < array.length; i++) {
67
- const val = array[i];
68
- if (Array.isArray(val)) {
69
- sql +=
70
- (i === 0 ? '' : ', ') + '(' + arrayToList(val, finalEscape, ctx) + ')';
71
- } else {
72
- sql += (i === 0 ? '' : ', ') + finalEscape(val, ctx);
73
- }
74
- }
75
- return sql;
76
- }
77
-
78
- function bufferToString(buffer) {
79
- return 'X' + escapeString(buffer.toString('hex'));
80
- }
81
-
82
- function escapeString(val, finalEscape, ctx) {
83
- let chunkIndex = (charsRegex.lastIndex = 0);
84
- let escapedVal = '';
85
- let match;
86
-
87
- while ((match = charsRegex.exec(val))) {
88
- escapedVal += val.slice(chunkIndex, match.index) + charsMap[match[0]];
89
- chunkIndex = charsRegex.lastIndex;
90
- }
91
-
92
- if (chunkIndex === 0) {
93
- // Nothing was escaped
94
- return "'" + val + "'";
95
- }
96
-
97
- if (chunkIndex < val.length) {
98
- return "'" + escapedVal + val.slice(chunkIndex) + "'";
99
- }
100
-
101
- return "'" + escapedVal + "'";
102
- }
103
-
104
- function dateToString(date, finalEscape, ctx = {}) {
105
- const timeZone = ctx.timeZone || 'local';
106
-
107
- const dt = new Date(date);
108
- let year;
109
- let month;
110
- let day;
111
- let hour;
112
- let minute;
113
- let second;
114
- let millisecond;
115
-
116
- if (timeZone === 'local') {
117
- year = dt.getFullYear();
118
- month = dt.getMonth() + 1;
119
- day = dt.getDate();
120
- hour = dt.getHours();
121
- minute = dt.getMinutes();
122
- second = dt.getSeconds();
123
- millisecond = dt.getMilliseconds();
124
- } else {
125
- const tz = convertTimezone(timeZone);
126
-
127
- if (tz !== false && tz !== 0) {
128
- dt.setTime(dt.getTime() + tz * 60000);
129
- }
130
-
131
- year = dt.getUTCFullYear();
132
- month = dt.getUTCMonth() + 1;
133
- day = dt.getUTCDate();
134
- hour = dt.getUTCHours();
135
- minute = dt.getUTCMinutes();
136
- second = dt.getUTCSeconds();
137
- millisecond = dt.getUTCMilliseconds();
138
- }
139
-
140
- // YYYY-MM-DD HH:mm:ss.mmm
141
- return (
142
- zeroPad(year, 4) +
143
- '-' +
144
- zeroPad(month, 2) +
145
- '-' +
146
- zeroPad(day, 2) +
147
- ' ' +
148
- zeroPad(hour, 2) +
149
- ':' +
150
- zeroPad(minute, 2) +
151
- ':' +
152
- zeroPad(second, 2) +
153
- '.' +
154
- zeroPad(millisecond, 3)
155
- );
156
- }
157
-
158
- function zeroPad(number, length) {
159
- number = number.toString();
160
- while (number.length < length) {
161
- number = '0' + number;
162
- }
163
- return number;
164
- }
165
-
166
- function convertTimezone(tz) {
167
- if (tz === 'Z') {
168
- return 0;
169
- }
170
- const m = tz.match(/([+\-\s])(\d\d):?(\d\d)?/);
171
- if (m) {
172
- return (
173
- (m[1] == '-' ? -1 : 1) *
174
- (parseInt(m[2], 10) + (m[3] ? parseInt(m[3], 10) : 0) / 60) *
175
- 60
176
- );
177
- }
178
- return false;
179
- }
180
-
181
- module.exports = {
182
- arrayToList,
183
- bufferToString,
184
- dateToString,
185
- escapeString,
186
- charsRegex,
187
- charsMap,
188
- escapeObject,
189
- makeEscape,
190
- };
1
+ /*eslint max-len: 0, no-var:0 */
2
+
3
+ const charsRegex = /[\0\b\t\n\r\x1a"'\\]/g; // eslint-disable-line no-control-regex
4
+ const charsMap = {
5
+ '\0': '\\0',
6
+ '\b': '\\b',
7
+ '\t': '\\t',
8
+ '\n': '\\n',
9
+ '\r': '\\r',
10
+ '\x1a': '\\Z',
11
+ '"': '\\"',
12
+ "'": "\\'",
13
+ '\\': '\\\\',
14
+ };
15
+
16
+ function wrapEscape(escapeFn) {
17
+ return function finalEscape(val, ctx = {}) {
18
+ return escapeFn(val, finalEscape, ctx);
19
+ };
20
+ }
21
+
22
+ function makeEscape(config = {}) {
23
+ const finalEscapeDate = config.escapeDate || dateToString;
24
+ const finalEscapeArray = config.escapeArray || arrayToList;
25
+ const finalEscapeBuffer = config.escapeBuffer || bufferToString;
26
+ const finalEscapeString = config.escapeString || escapeString;
27
+ const finalEscapeObject = config.escapeObject || escapeObject;
28
+ const finalWrap = config.wrap || wrapEscape;
29
+
30
+ function escapeFn(val, finalEscape, ctx) {
31
+ if (val === undefined || val === null) {
32
+ return 'NULL';
33
+ }
34
+ switch (typeof val) {
35
+ case 'boolean':
36
+ return val ? 'true' : 'false';
37
+ case 'number':
38
+ return val + '';
39
+ case 'object':
40
+ if (val instanceof Date) {
41
+ val = finalEscapeDate(val, finalEscape, ctx);
42
+ } else if (Array.isArray(val)) {
43
+ return finalEscapeArray(val, finalEscape, ctx);
44
+ } else if (Buffer.isBuffer(val)) {
45
+ return finalEscapeBuffer(val, finalEscape, ctx);
46
+ } else {
47
+ return finalEscapeObject(val, finalEscape, ctx);
48
+ }
49
+ }
50
+ return finalEscapeString(val, finalEscape, ctx);
51
+ }
52
+
53
+ return finalWrap ? finalWrap(escapeFn) : escapeFn;
54
+ }
55
+
56
+ function escapeObject(val, finalEscape, ctx) {
57
+ if (val && typeof val.toSQL === 'function') {
58
+ return val.toSQL(ctx);
59
+ } else {
60
+ return JSON.stringify(val);
61
+ }
62
+ }
63
+
64
+ function arrayToList(array, finalEscape, ctx) {
65
+ let sql = '';
66
+ for (let i = 0; i < array.length; i++) {
67
+ const val = array[i];
68
+ if (Array.isArray(val)) {
69
+ sql +=
70
+ (i === 0 ? '' : ', ') + '(' + arrayToList(val, finalEscape, ctx) + ')';
71
+ } else {
72
+ sql += (i === 0 ? '' : ', ') + finalEscape(val, ctx);
73
+ }
74
+ }
75
+ return sql;
76
+ }
77
+
78
+ function bufferToString(buffer) {
79
+ return 'X' + escapeString(buffer.toString('hex'));
80
+ }
81
+
82
+ function escapeString(val, finalEscape, ctx) {
83
+ let chunkIndex = (charsRegex.lastIndex = 0);
84
+ let escapedVal = '';
85
+ let match;
86
+
87
+ while ((match = charsRegex.exec(val))) {
88
+ escapedVal += val.slice(chunkIndex, match.index) + charsMap[match[0]];
89
+ chunkIndex = charsRegex.lastIndex;
90
+ }
91
+
92
+ if (chunkIndex === 0) {
93
+ // Nothing was escaped
94
+ return "'" + val + "'";
95
+ }
96
+
97
+ if (chunkIndex < val.length) {
98
+ return "'" + escapedVal + val.slice(chunkIndex) + "'";
99
+ }
100
+
101
+ return "'" + escapedVal + "'";
102
+ }
103
+
104
+ function dateToString(date, finalEscape, ctx = {}) {
105
+ const timeZone = ctx.timeZone || 'local';
106
+
107
+ const dt = new Date(date);
108
+ let year;
109
+ let month;
110
+ let day;
111
+ let hour;
112
+ let minute;
113
+ let second;
114
+ let millisecond;
115
+
116
+ if (timeZone === 'local') {
117
+ year = dt.getFullYear();
118
+ month = dt.getMonth() + 1;
119
+ day = dt.getDate();
120
+ hour = dt.getHours();
121
+ minute = dt.getMinutes();
122
+ second = dt.getSeconds();
123
+ millisecond = dt.getMilliseconds();
124
+ } else {
125
+ const tz = convertTimezone(timeZone);
126
+
127
+ if (tz !== false && tz !== 0) {
128
+ dt.setTime(dt.getTime() + tz * 60000);
129
+ }
130
+
131
+ year = dt.getUTCFullYear();
132
+ month = dt.getUTCMonth() + 1;
133
+ day = dt.getUTCDate();
134
+ hour = dt.getUTCHours();
135
+ minute = dt.getUTCMinutes();
136
+ second = dt.getUTCSeconds();
137
+ millisecond = dt.getUTCMilliseconds();
138
+ }
139
+
140
+ // YYYY-MM-DD HH:mm:ss.mmm
141
+ return (
142
+ zeroPad(year, 4) +
143
+ '-' +
144
+ zeroPad(month, 2) +
145
+ '-' +
146
+ zeroPad(day, 2) +
147
+ ' ' +
148
+ zeroPad(hour, 2) +
149
+ ':' +
150
+ zeroPad(minute, 2) +
151
+ ':' +
152
+ zeroPad(second, 2) +
153
+ '.' +
154
+ zeroPad(millisecond, 3)
155
+ );
156
+ }
157
+
158
+ function zeroPad(number, length) {
159
+ number = number.toString();
160
+ while (number.length < length) {
161
+ number = '0' + number;
162
+ }
163
+ return number;
164
+ }
165
+
166
+ function convertTimezone(tz) {
167
+ if (tz === 'Z') {
168
+ return 0;
169
+ }
170
+ const m = tz.match(/([+\-\s])(\d\d):?(\d\d)?/);
171
+ if (m) {
172
+ return (
173
+ (m[1] == '-' ? -1 : 1) *
174
+ (parseInt(m[2], 10) + (m[3] ? parseInt(m[3], 10) : 0) / 60) *
175
+ 60
176
+ );
177
+ }
178
+ return false;
179
+ }
180
+
181
+ module.exports = {
182
+ arrayToList,
183
+ bufferToString,
184
+ dateToString,
185
+ escapeString,
186
+ charsRegex,
187
+ charsMap,
188
+ escapeObject,
189
+ makeEscape,
190
+ };