knex 1.0.7 → 2.2.0
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 +51 -3
- package/CONTRIBUTING.md +10 -0
- package/UPGRADING.md +4 -0
- package/lib/client.js +1 -4
- package/lib/dialects/cockroachdb/crdb-columncompiler.js +14 -0
- package/lib/dialects/cockroachdb/index.js +5 -0
- package/lib/dialects/index.js +34 -0
- package/lib/dialects/mssql/schema/mssql-compiler.js +9 -2
- package/lib/dialects/mysql/query/mysql-querycompiler.js +1 -1
- package/lib/dialects/mysql/schema/mysql-compiler.js +2 -2
- package/lib/dialects/oracledb/index.js +2 -1
- package/lib/dialects/postgres/schema/pg-columncompiler.js +7 -1
- package/lib/dialects/postgres/schema/pg-compiler.js +2 -2
- package/lib/dialects/postgres/schema/pg-tablecompiler.js +33 -6
- package/lib/dialects/sqlite3/index.js +11 -4
- package/lib/dialects/sqlite3/query/sqlite-querycompiler.js +1 -1
- package/lib/execution/runner.js +2 -9
- package/lib/knex-builder/Knex.js +28 -0
- package/lib/knex-builder/internal/config-resolver.js +2 -3
- package/lib/knex-builder/internal/parse-connection.js +4 -2
- package/lib/migrations/migrate/MigrationGenerator.js +1 -1
- package/lib/migrations/migrate/stub/js-schema.stub +22 -0
- package/lib/migrations/migrate/stub/ts-schema.stub +21 -0
- package/lib/schema/builder.js +12 -0
- package/lib/schema/columnbuilder.js +12 -0
- package/lib/schema/columncompiler.js +4 -2
- package/lib/schema/tablebuilder.js +12 -0
- package/lib/schema/viewbuilder.js +12 -0
- package/package.json +29 -24
- package/scripts/clean.js +29 -0
- package/scripts/runkit-example.js +1 -1
- package/scripts/update_gitignore_for_tsc_output.js +85 -0
- package/types/index.d.ts +843 -392
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knex",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.2.0",
|
|
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",
|
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
"node": ">=12"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
+
"build": "npm run build:gitignore && npm run build:ts",
|
|
12
|
+
"clean": "node scripts/clean.js",
|
|
13
|
+
"build:ts": "tsc",
|
|
14
|
+
"build:gitignore": "node scripts/update_gitignore_for_tsc_output.js run",
|
|
11
15
|
"format": "prettier --write \"{lib,bin,scripts,test}/**/*.js\"",
|
|
12
16
|
"debug:test": "mocha --inspect-brk --exit -t 0 test/all-tests-suite.js",
|
|
13
17
|
"debug:tape": "node --inspect-brk test/tape/index.js",
|
|
@@ -51,10 +55,12 @@
|
|
|
51
55
|
"db:stop:oracle": "docker-compose -f scripts/docker-compose.yml down",
|
|
52
56
|
"stress:init": "docker-compose -f scripts/stress-test/docker-compose.yml up --no-start && docker-compose -f scripts/stress-test/docker-compose.yml start",
|
|
53
57
|
"stress:test": "node scripts/stress-test/knex-stress-test.js | grep -A 5 -B 60 -- '- STATS '",
|
|
54
|
-
"stress:destroy": "docker-compose -f scripts/stress-test/docker-compose.yml stop"
|
|
58
|
+
"stress:destroy": "docker-compose -f scripts/stress-test/docker-compose.yml stop",
|
|
59
|
+
"prepare": "husky install && npm run clean && npm run build",
|
|
60
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
55
61
|
},
|
|
56
62
|
"dependencies": {
|
|
57
|
-
"colorette": "2.0.
|
|
63
|
+
"colorette": "2.0.19",
|
|
58
64
|
"commander": "^9.1.0",
|
|
59
65
|
"debug": "4.3.4",
|
|
60
66
|
"escalade": "^3.1.1",
|
|
@@ -85,7 +91,7 @@
|
|
|
85
91
|
"pg-native": {
|
|
86
92
|
"optional": true
|
|
87
93
|
},
|
|
88
|
-
"
|
|
94
|
+
"sqlite3": {
|
|
89
95
|
"optional": true
|
|
90
96
|
},
|
|
91
97
|
"better-sqlite3": {
|
|
@@ -94,13 +100,12 @@
|
|
|
94
100
|
},
|
|
95
101
|
"lint-staged": {
|
|
96
102
|
"*.{js,json}": [
|
|
97
|
-
"prettier --write"
|
|
98
|
-
"git add"
|
|
103
|
+
"prettier --write"
|
|
99
104
|
]
|
|
100
105
|
},
|
|
101
106
|
"devDependencies": {
|
|
102
|
-
"@
|
|
103
|
-
"@
|
|
107
|
+
"@tsconfig/recommended": "^1.0.1",
|
|
108
|
+
"@types/node": "^18.0.4",
|
|
104
109
|
"better-sqlite3": "^7.5.1",
|
|
105
110
|
"chai": "^4.3.6",
|
|
106
111
|
"chai-as-promised": "^7.1.1",
|
|
@@ -113,11 +118,11 @@
|
|
|
113
118
|
"eslint-config-prettier": "^8.5.0",
|
|
114
119
|
"eslint-plugin-import": "^2.26.0",
|
|
115
120
|
"eslint-plugin-mocha-no-only": "^1.1.1",
|
|
116
|
-
"husky": "^
|
|
117
|
-
"jake": "^8.
|
|
121
|
+
"husky": "^8.0.1",
|
|
122
|
+
"jake": "^10.8.5",
|
|
118
123
|
"JSONStream": "^1.3.5",
|
|
119
|
-
"lint-staged": "^
|
|
120
|
-
"mocha": "^
|
|
124
|
+
"lint-staged": "^13.0.0",
|
|
125
|
+
"mocha": "^10.0.0",
|
|
121
126
|
"mock-fs": "^5.1.2",
|
|
122
127
|
"mysql": "^2.18.1",
|
|
123
128
|
"mysql2": "^2.3.3",
|
|
@@ -127,16 +132,17 @@
|
|
|
127
132
|
"pg-query-stream": "^4.2.1",
|
|
128
133
|
"prettier": "2.6.2",
|
|
129
134
|
"rimraf": "^3.0.2",
|
|
130
|
-
"sinon": "^
|
|
135
|
+
"sinon": "^14.0.0",
|
|
131
136
|
"sinon-chai": "^3.7.0",
|
|
132
137
|
"source-map-support": "^0.5.21",
|
|
138
|
+
"sqlite3": "^5.0.4",
|
|
133
139
|
"tap-spec": "^5.0.0",
|
|
134
140
|
"tape": "^5.5.3",
|
|
135
141
|
"tedious": "^14.4.0",
|
|
136
142
|
"toxiproxy-node-client": "^2.0.6",
|
|
137
143
|
"ts-node": "^10.7.0",
|
|
138
|
-
"tsd": "^0.
|
|
139
|
-
"typescript": "4.
|
|
144
|
+
"tsd": "^0.22.0",
|
|
145
|
+
"typescript": "4.7.4"
|
|
140
146
|
},
|
|
141
147
|
"buildDependencies": [
|
|
142
148
|
"rimraf"
|
|
@@ -193,9 +199,9 @@
|
|
|
193
199
|
}
|
|
194
200
|
],
|
|
195
201
|
"browser": {
|
|
196
|
-
"./lib/migrate/Migrator.js": "./lib/util/noop.js",
|
|
202
|
+
"./lib/migrations/migrate/Migrator.js": "./lib/util/noop.js",
|
|
197
203
|
"./lib/bin/cli.js": "./lib/util/noop.js",
|
|
198
|
-
"./lib/seed/Seeder.js": "./lib/util/noop.js",
|
|
204
|
+
"./lib/migrations/seed/Seeder.js": "./lib/util/noop.js",
|
|
199
205
|
"tedious": false,
|
|
200
206
|
"mysql": false,
|
|
201
207
|
"mysql2": false,
|
|
@@ -204,7 +210,6 @@
|
|
|
204
210
|
"pg-query-stream": false,
|
|
205
211
|
"oracle": false,
|
|
206
212
|
"sqlite3": false,
|
|
207
|
-
"@vscode/sqlite3": false,
|
|
208
213
|
"better-sqlite3": false,
|
|
209
214
|
"oracledb": false
|
|
210
215
|
},
|
|
@@ -214,7 +219,12 @@
|
|
|
214
219
|
},
|
|
215
220
|
"files": [
|
|
216
221
|
"bin/*",
|
|
217
|
-
"lib
|
|
222
|
+
"lib/",
|
|
223
|
+
"lib/**/*.js",
|
|
224
|
+
"!lib/**/*.ts",
|
|
225
|
+
"!lib/**/*.d.ts",
|
|
226
|
+
"!lib/**/*.js.map",
|
|
227
|
+
"!lib/.gitignore",
|
|
218
228
|
"scripts/*",
|
|
219
229
|
"types/index.d.ts",
|
|
220
230
|
"types/result.d.ts",
|
|
@@ -242,11 +252,6 @@
|
|
|
242
252
|
"lib/dialects/oracledb"
|
|
243
253
|
]
|
|
244
254
|
},
|
|
245
|
-
"husky": {
|
|
246
|
-
"hooks": {
|
|
247
|
-
"pre-commit": "lint-staged"
|
|
248
|
-
}
|
|
249
|
-
},
|
|
250
255
|
"tsd": {
|
|
251
256
|
"directory": "test-tsd",
|
|
252
257
|
"compilerOptions": {
|
package/scripts/clean.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs')
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const { execSync } = require("child_process");
|
|
6
|
+
|
|
7
|
+
function main() {
|
|
8
|
+
const repoDir = path.dirname(__dirname)
|
|
9
|
+
const gitDir = path.join(repoDir, '.git')
|
|
10
|
+
const gitDirExists = doesDirectoryExist(gitDir)
|
|
11
|
+
if (!gitDirExists) {
|
|
12
|
+
console.log("No .git directory detected so can not clean 'lib/'. Exiting.")
|
|
13
|
+
process.exit(0)
|
|
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')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function doesDirectoryExist(p) {
|
|
23
|
+
if (fs.existsSync(p)) {
|
|
24
|
+
return fs.lstatSync(p).isDirectory()
|
|
25
|
+
}
|
|
26
|
+
return false
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
main()
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const path = require('path')
|
|
4
|
+
const fs = require('fs')
|
|
5
|
+
|
|
6
|
+
// Directory constants
|
|
7
|
+
const scriptDirectory = __dirname
|
|
8
|
+
const repoDirectory = path.join(scriptDirectory, '..')
|
|
9
|
+
const libDirectory = path.join(repoDirectory, 'lib')
|
|
10
|
+
|
|
11
|
+
const helpText = `
|
|
12
|
+
Helper script to update lib/.gitignore for all .js files from .ts files.
|
|
13
|
+
|
|
14
|
+
update_gitignore_for_tsc_output.js COMMAND
|
|
15
|
+
|
|
16
|
+
COMMAND:
|
|
17
|
+
run: Update lib/.gitignore file.
|
|
18
|
+
help: Print this menu.
|
|
19
|
+
|
|
20
|
+
NOTES FOR USAGE:
|
|
21
|
+
1. This script is tested to work on Ubuntu 18.04 LTS.
|
|
22
|
+
`
|
|
23
|
+
|
|
24
|
+
const gitignoreHeader = `# DO NOT EDIT, GENERATED BY: scripts/update_gitignore_for_tsc_output.js
|
|
25
|
+
|
|
26
|
+
# Do not include tsc generated type definitions
|
|
27
|
+
**/*.d.ts
|
|
28
|
+
|
|
29
|
+
# Do not include tsc source maps
|
|
30
|
+
**/*.js.map
|
|
31
|
+
|
|
32
|
+
# Do not include .js files from .ts files
|
|
33
|
+
`
|
|
34
|
+
|
|
35
|
+
function main(cliCommand) {
|
|
36
|
+
if (cliCommand === 'run') {
|
|
37
|
+
console.log('Generating lib/.gitignore ...')
|
|
38
|
+
|
|
39
|
+
// Find all .ts files in lib/
|
|
40
|
+
const directoriesToProcess = [libDirectory]
|
|
41
|
+
const tsFiles = []
|
|
42
|
+
while (directoriesToProcess.length > 0) {
|
|
43
|
+
const directory = directoriesToProcess.pop()
|
|
44
|
+
if (!fs.existsSync(directory)) {
|
|
45
|
+
throw new Error("Directory doesn't exist:", directory)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const files = fs.readdirSync(directory)
|
|
49
|
+
files.forEach((file) => {
|
|
50
|
+
const filename = path.join(directory, file)
|
|
51
|
+
const stat = fs.lstatSync(filename)
|
|
52
|
+
if (stat.isDirectory()) {
|
|
53
|
+
directoriesToProcess.push(filename)
|
|
54
|
+
} else if (filename.endsWith('.ts') && !filename.endsWith('.d.ts')) {
|
|
55
|
+
tsFiles.push(filename)
|
|
56
|
+
console.log('Found .ts file:', filename)
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Get paths of .js files to ignore
|
|
62
|
+
const jsFilesToIgnore = tsFiles.map((filepath) => {
|
|
63
|
+
// Cuts off `${libDirectory}/`
|
|
64
|
+
const relativeTsPath = filepath.slice(libDirectory.length + 1)
|
|
65
|
+
// Swaps .ts for .js file ending
|
|
66
|
+
const relativeJsPath = relativeTsPath.slice(0, relativeTsPath.length - 3) + '.js'
|
|
67
|
+
return relativeJsPath
|
|
68
|
+
})
|
|
69
|
+
const jsFilesToIgnoreString = jsFilesToIgnore.join('\n')
|
|
70
|
+
const libGitignorePath = path.join(libDirectory, '.gitignore')
|
|
71
|
+
fs.writeFileSync(libGitignorePath, gitignoreHeader + jsFilesToIgnoreString + '\n')
|
|
72
|
+
console.log('DONE')
|
|
73
|
+
} else if (['help', '--help', '-h', undefined].includes(cliCommand)) {
|
|
74
|
+
console.log(helpText)
|
|
75
|
+
} else {
|
|
76
|
+
console.log(`Unsupported command: ${cliCommand}`)
|
|
77
|
+
console.log("Try running with 'help' to see supported commands.")
|
|
78
|
+
process.exit(1)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Main script logic
|
|
83
|
+
const cliCommand = process.argv[2]
|
|
84
|
+
// Start the bash app's main function
|
|
85
|
+
main(cliCommand)
|