knex 2.4.0 → 2.4.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Master (Unreleased)
2
2
 
3
+ # 2.4.2 - 22 January, 2022
4
+
5
+ ### Bug fixes
6
+
7
+ - CLI: Fix incorrent EOL causing errors on Linux #5455
8
+
9
+ # 2.4.1 - 18 January, 2022
10
+
11
+ ### Bug fixes
12
+
13
+ - PostgreSQL: Fix Malformed array literal 2.4.0 Regression #5439
14
+
3
15
  # 2.4.0 - 06 January, 2022
4
16
 
5
17
  ### New features:
package/bin/cli.js CHANGED
@@ -218,7 +218,7 @@ function invoke() {
218
218
  .action(async (name) => {
219
219
  try {
220
220
  const opts = commander.opts();
221
- const instance = await initKnex(env, opts, true); // Skip config check, we don't really care about client when creating migrations
221
+ const instance = await initKnex(env, opts, true); // Skip config check, we don't really care about client when creating migrations
222
222
  const ext = getMigrationExtension(env, opts);
223
223
  const configOverrides = { extension: ext };
224
224
 
@@ -233,7 +233,7 @@ function invoke() {
233
233
  success(color.green(`Created Migration: ${name}`));
234
234
  })
235
235
  .catch(exit);
236
- } catch(err) {
236
+ } catch (err) {
237
237
  exit(err);
238
238
  }
239
239
  });
@@ -397,7 +397,8 @@ function invoke() {
397
397
  }
398
398
 
399
399
  if (opts.timestampFilenamePrefix) {
400
- configOverrides.timestampFilenamePrefix = opts.timestampFilenamePrefix;
400
+ configOverrides.timestampFilenamePrefix =
401
+ opts.timestampFilenamePrefix;
401
402
  }
402
403
 
403
404
  instance.seed
@@ -406,9 +407,9 @@ function invoke() {
406
407
  success(color.green(`Created seed file: ${name}`));
407
408
  })
408
409
  .catch(exit);
409
- } catch(err) {
410
+ } catch (err) {
410
411
  exit(err);
411
- }
412
+ }
412
413
  });
413
414
 
414
415
  commander
package/lib/client.js CHANGED
@@ -216,11 +216,11 @@ class Client extends EventEmitter {
216
216
  const DEFAULT_ACQUIRE_TIMEOUT = 60000;
217
217
  const timeouts = [
218
218
  this.config.acquireConnectionTimeout,
219
- poolConfig.acquireTimeoutMillis
219
+ poolConfig.acquireTimeoutMillis,
220
220
  ].filter((timeout) => timeout !== undefined);
221
221
 
222
222
  if (!timeouts.length) {
223
- timeouts.push(DEFAULT_ACQUIRE_TIMEOUT)
223
+ timeouts.push(DEFAULT_ACQUIRE_TIMEOUT);
224
224
  }
225
225
 
226
226
  // acquire connection timeout can be set on config or config.pool
@@ -401,7 +401,7 @@ class Client extends EventEmitter {
401
401
  if (i > 0) str += ', ';
402
402
  let value = values[i];
403
403
  // json columns can have object in values.
404
- if (isPlainObject(value) || Array.isArray(value)) {
404
+ if (isPlainObject(value)) {
405
405
  value = JSON.stringify(value);
406
406
  }
407
407
  str += this.parameter(
@@ -120,7 +120,9 @@ class SchemaCompiler_PG extends SchemaCompiler {
120
120
 
121
121
  refreshMaterializedView(viewName, concurrently = false) {
122
122
  this.pushQuery({
123
- sql: `refresh materialized view${concurrently ? " concurrently" : ""} ${this.formatter.wrap(viewName)}`,
123
+ sql: `refresh materialized view${
124
+ concurrently ? ' concurrently' : ''
125
+ } ${this.formatter.wrap(viewName)}`,
124
126
  });
125
127
  }
126
128
 
@@ -50,7 +50,7 @@ knex.ColumnBuilder = {
50
50
  },
51
51
  };
52
52
 
53
- knex.TableBuilder = {
53
+ knex.TableBuilder = {
54
54
  extend: function (methodName, fn) {
55
55
  TableBuilder.extend(methodName, fn);
56
56
  },
@@ -41,7 +41,9 @@ class MigrationGenerator {
41
41
 
42
42
  _getNewMigrationName(name) {
43
43
  if (name[0] === '-') name = name.slice(1);
44
- return yyyymmddhhmmss() + '_' + name + '.' + this.config.extension.split('-')[0];
44
+ return (
45
+ yyyymmddhhmmss() + '_' + name + '.' + this.config.extension.split('-')[0]
46
+ );
45
47
  }
46
48
 
47
49
  _getNewMigrationPath(name) {
@@ -97,9 +97,10 @@ class SchemaBuilder extends EventEmitter {
97
97
  };
98
98
  });
99
99
 
100
-
101
100
  SchemaBuilder.extend = (methodName, fn) => {
102
- if (Object.prototype.hasOwnProperty.call(SchemaBuilder.prototype, methodName)) {
101
+ if (
102
+ Object.prototype.hasOwnProperty.call(SchemaBuilder.prototype, methodName)
103
+ ) {
103
104
  throw new Error(
104
105
  `Can't extend SchemaBuilder with existing method ('${methodName}').`
105
106
  );
@@ -88,9 +88,10 @@ ColumnBuilder.prototype.notNull = ColumnBuilder.prototype.notNullable =
88
88
  };
89
89
  });
90
90
 
91
-
92
91
  ColumnBuilder.extend = (methodName, fn) => {
93
- if (Object.prototype.hasOwnProperty.call(ColumnBuilder.prototype, methodName)) {
92
+ if (
93
+ Object.prototype.hasOwnProperty.call(ColumnBuilder.prototype, methodName)
94
+ ) {
94
95
  throw new Error(
95
96
  `Can't extend ColumnBuilder with existing method ('${methodName}').`
96
97
  );
@@ -361,9 +361,10 @@ AlterMethods.dropColumn = AlterMethods.dropColumns = function () {
361
361
  return this;
362
362
  };
363
363
 
364
-
365
364
  TableBuilder.extend = (methodName, fn) => {
366
- if (Object.prototype.hasOwnProperty.call(TableBuilder.prototype, methodName)) {
365
+ if (
366
+ Object.prototype.hasOwnProperty.call(TableBuilder.prototype, methodName)
367
+ ) {
367
368
  throw new Error(
368
369
  `Can't extend TableBuilder with existing method ('${methodName}').`
369
370
  );
@@ -79,7 +79,6 @@ const AlterMethods = {
79
79
 
80
80
  helpers.addQueryContext(ViewBuilder);
81
81
 
82
-
83
82
  ViewBuilder.extend = (methodName, fn) => {
84
83
  if (Object.prototype.hasOwnProperty.call(ViewBuilder.prototype, methodName)) {
85
84
  throw new Error(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knex",
3
- "version": "2.4.0",
3
+ "version": "2.4.2",
4
4
  "description": "A batteries-included SQL query & schema builder for PostgresSQL, MySQL, CockroachDB, MSSQL and SQLite3",
5
5
  "main": "knex",
6
6
  "types": "types/index.d.ts",
@@ -13,10 +13,11 @@
13
13
  "build:ts": "tsc",
14
14
  "build:gitignore": "node scripts/update_gitignore_for_tsc_output.js run",
15
15
  "format": "prettier --write \"{lib,bin,scripts,test}/**/*.js\"",
16
+ "format:check-difference": "prettier --list-different \"{lib,bin,scripts,test}/**/*.js\"",
16
17
  "debug:test": "mocha --inspect-brk --exit -t 0 test/all-tests-suite.js",
17
18
  "debug:tape": "node --inspect-brk test/tape/index.js",
18
19
  "coveralls": "nyc report --reporter=lcov",
19
- "lint": "eslint \"lib/**/*.js\" \"test/**/*.js\"",
20
+ "lint": "eslint \"lib/**/*.js\" \"test/**/*.js\" \"bin/**/*.js\"",
20
21
  "lint:types": "tsd && dtslint types",
21
22
  "lint:everything": "npm run lint:types && npm run lint",
22
23
  "test:unit": "npm run test:unit-only && npm run test:cli",
@@ -57,7 +58,7 @@
57
58
  "stress:test": "node scripts/stress-test/knex-stress-test.js | grep -A 5 -B 60 -- '- STATS '",
58
59
  "stress:destroy": "docker-compose -f scripts/stress-test/docker-compose.yml stop",
59
60
  "prepare": "husky install && npm run clean && npm run build",
60
- "prepublishOnly": "npm run clean && npm run build"
61
+ "prepublishOnly": "npm run format:check-difference && npm run lint && npm run clean && npm run build"
61
62
  },
62
63
  "dependencies": {
63
64
  "colorette": "2.0.19",
@@ -114,10 +115,11 @@
114
115
  "coveralls": "^3.1.1",
115
116
  "cross-env": "^7.0.3",
116
117
  "dtslint": "4.2.1",
117
- "eslint": "^8.13.0",
118
- "eslint-config-prettier": "^8.5.0",
118
+ "eslint": "^8.32.0",
119
+ "eslint-config-prettier": "^8.6.0",
119
120
  "eslint-plugin-import": "^2.26.0",
120
121
  "eslint-plugin-mocha-no-only": "^1.1.1",
122
+ "eslint-plugin-prettier": "^4.2.1",
121
123
  "husky": "^8.0.1",
122
124
  "jake": "^10.8.5",
123
125
  "JSONStream": "^1.3.5",
@@ -130,7 +132,7 @@
130
132
  "oracledb": "^5.4.0",
131
133
  "pg": "^8.8.0",
132
134
  "pg-query-stream": "^4.2.4",
133
- "prettier": "2.6.2",
135
+ "prettier": "2.8.3",
134
136
  "rimraf": "^3.0.2",
135
137
  "sinon": "^15.0.1",
136
138
  "sinon-chai": "^3.7.0",
package/scripts/clean.js CHANGED
@@ -1,29 +1,31 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const fs = require('fs')
4
- const path = require('path')
5
- const { execSync } = require("child_process");
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const { execSync } = require('child_process');
6
6
 
7
7
  function main() {
8
- const repoDir = path.dirname(__dirname)
9
- const gitDir = path.join(repoDir, '.git')
10
- const gitDirExists = doesDirectoryExist(gitDir)
8
+ const repoDir = path.dirname(__dirname);
9
+ const gitDir = path.join(repoDir, '.git');
10
+ const gitDirExists = doesDirectoryExist(gitDir);
11
11
  if (!gitDirExists) {
12
- console.log("No .git directory detected so can not clean 'lib/'. Exiting.")
13
- process.exit(0)
12
+ console.log("No .git directory detected so can not clean 'lib/'. Exiting.");
13
+ process.exit(0);
14
14
  }
15
- console.log("Cleaning 'lib/' of outputted files from Typescript compilation ...")
16
- const cmd = 'git clean -f -X lib/'
17
- const output = execSync(cmd, { cwd: repoDir })
18
- console.log(output.toString('utf8'))
19
- console.log('Done')
15
+ console.log(
16
+ "Cleaning 'lib/' of outputted files from Typescript compilation ..."
17
+ );
18
+ const cmd = 'git clean -f -X lib/';
19
+ const output = execSync(cmd, { cwd: repoDir });
20
+ console.log(output.toString('utf8'));
21
+ console.log('Done');
20
22
  }
21
23
 
22
24
  function doesDirectoryExist(p) {
23
25
  if (fs.existsSync(p)) {
24
- return fs.lstatSync(p).isDirectory()
26
+ return fs.lstatSync(p).isDirectory();
25
27
  }
26
- return false
28
+ return false;
27
29
  }
28
30
 
29
- main()
31
+ main();
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const path = require('path')
4
- const fs = require('fs')
3
+ const path = require('path');
4
+ const fs = require('fs');
5
5
 
6
6
  // Directory constants
7
- const scriptDirectory = __dirname
8
- const repoDirectory = path.join(scriptDirectory, '..')
9
- const libDirectory = path.join(repoDirectory, 'lib')
7
+ const scriptDirectory = __dirname;
8
+ const repoDirectory = path.join(scriptDirectory, '..');
9
+ const libDirectory = path.join(repoDirectory, 'lib');
10
10
 
11
11
  const helpText = `
12
12
  Helper script to update lib/.gitignore for all .js files from .ts files.
@@ -19,7 +19,7 @@ Helper script to update lib/.gitignore for all .js files from .ts files.
19
19
 
20
20
  NOTES FOR USAGE:
21
21
  1. This script is tested to work on Ubuntu 18.04 LTS.
22
- `
22
+ `;
23
23
 
24
24
  const gitignoreHeader = `# DO NOT EDIT, GENERATED BY: scripts/update_gitignore_for_tsc_output.js
25
25
 
@@ -30,57 +30,61 @@ const gitignoreHeader = `# DO NOT EDIT, GENERATED BY: scripts/update_gitignore_f
30
30
  **/*.js.map
31
31
 
32
32
  # Do not include .js files from .ts files
33
- `
33
+ `;
34
34
 
35
35
  function main(cliCommand) {
36
36
  if (cliCommand === 'run') {
37
- console.log('Generating lib/.gitignore ...')
37
+ console.log('Generating lib/.gitignore ...');
38
38
 
39
39
  // Find all .ts files in lib/
40
- const directoriesToProcess = [libDirectory]
41
- const tsFiles = []
40
+ const directoriesToProcess = [libDirectory];
41
+ const tsFiles = [];
42
42
  while (directoriesToProcess.length > 0) {
43
- const directory = directoriesToProcess.pop()
43
+ const directory = directoriesToProcess.pop();
44
44
  if (!fs.existsSync(directory)) {
45
- throw new Error("Directory doesn't exist:", directory)
45
+ throw new Error("Directory doesn't exist:", directory);
46
46
  }
47
47
 
48
- const files = fs.readdirSync(directory)
48
+ const files = fs.readdirSync(directory);
49
49
  files.forEach((file) => {
50
- const filename = path.join(directory, file)
51
- const stat = fs.lstatSync(filename)
50
+ const filename = path.join(directory, file);
51
+ const stat = fs.lstatSync(filename);
52
52
  if (stat.isDirectory()) {
53
- directoriesToProcess.push(filename)
53
+ directoriesToProcess.push(filename);
54
54
  } else if (filename.endsWith('.ts') && !filename.endsWith('.d.ts')) {
55
- tsFiles.push(filename)
56
- console.log('Found .ts file:', filename)
55
+ tsFiles.push(filename);
56
+ console.log('Found .ts file:', filename);
57
57
  }
58
- })
58
+ });
59
59
  }
60
60
 
61
61
  // Get paths of .js files to ignore
62
62
  const jsFilesToIgnore = tsFiles.map((filepath) => {
63
63
  // Cuts off `${libDirectory}/`
64
- const relativeTsPath = filepath.slice(libDirectory.length + 1)
64
+ const relativeTsPath = filepath.slice(libDirectory.length + 1);
65
65
  // Swaps .ts for .js file ending
66
- const relativeJsPath = relativeTsPath.slice(0, relativeTsPath.length - 3) + '.js'
66
+ const relativeJsPath =
67
+ relativeTsPath.slice(0, relativeTsPath.length - 3) + '.js';
67
68
  // Always use POSIX-style path separators - .gitignore requires it
68
69
  return relativeJsPath.split(path.sep).join(path.posix.sep);
69
- })
70
- const jsFilesToIgnoreString = jsFilesToIgnore.join('\n')
71
- const libGitignorePath = path.join(libDirectory, '.gitignore')
72
- fs.writeFileSync(libGitignorePath, gitignoreHeader + jsFilesToIgnoreString + '\n')
73
- console.log('DONE')
70
+ });
71
+ const jsFilesToIgnoreString = jsFilesToIgnore.join('\n');
72
+ const libGitignorePath = path.join(libDirectory, '.gitignore');
73
+ fs.writeFileSync(
74
+ libGitignorePath,
75
+ gitignoreHeader + jsFilesToIgnoreString + '\n'
76
+ );
77
+ console.log('DONE');
74
78
  } else if (['help', '--help', '-h', undefined].includes(cliCommand)) {
75
- console.log(helpText)
79
+ console.log(helpText);
76
80
  } else {
77
- console.log(`Unsupported command: ${cliCommand}`)
78
- console.log("Try running with 'help' to see supported commands.")
79
- process.exit(1)
81
+ console.log(`Unsupported command: ${cliCommand}`);
82
+ console.log("Try running with 'help' to see supported commands.");
83
+ process.exit(1);
80
84
  }
81
85
  }
82
86
 
83
87
  // Main script logic
84
- const cliCommand = process.argv[2]
88
+ const cliCommand = process.argv[2];
85
89
  // Start the bash app's main function
86
- main(cliCommand)
90
+ main(cliCommand);