knex 3.2.2 → 3.2.4

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 (199) hide show
  1. package/CHANGELOG.md +2447 -2441
  2. package/CONTRIBUTING.md +190 -190
  3. package/LICENSE +22 -22
  4. package/README.md +156 -156
  5. package/UPGRADING.md +245 -245
  6. package/bin/cli.js +516 -516
  7. package/bin/knexfile-runtime-error.js +27 -27
  8. package/bin/utils/cli-config-utils.js +217 -217
  9. package/bin/utils/constants.js +7 -7
  10. package/bin/utils/migrationsLister.js +37 -37
  11. package/knex.js +23 -23
  12. package/knex.mjs +11 -11
  13. package/lib/builder-interface-augmenter.js +120 -120
  14. package/lib/client.js +585 -585
  15. package/lib/constants.js +61 -61
  16. package/lib/dialects/better-sqlite3/index.js +101 -101
  17. package/lib/dialects/cockroachdb/crdb-columncompiler.js +14 -14
  18. package/lib/dialects/cockroachdb/crdb-querybuilder.js +11 -11
  19. package/lib/dialects/cockroachdb/crdb-querycompiler.js +122 -122
  20. package/lib/dialects/cockroachdb/crdb-tablecompiler.js +46 -46
  21. package/lib/dialects/cockroachdb/crdb-viewcompiler.js +15 -15
  22. package/lib/dialects/cockroachdb/index.js +86 -86
  23. package/lib/dialects/index.js +34 -34
  24. package/lib/dialects/mssql/index.js +498 -498
  25. package/lib/dialects/mssql/mssql-formatter.js +34 -34
  26. package/lib/dialects/mssql/query/mssql-querycompiler.js +601 -601
  27. package/lib/dialects/mssql/schema/mssql-columncompiler.js +185 -185
  28. package/lib/dialects/mssql/schema/mssql-compiler.js +91 -91
  29. package/lib/dialects/mssql/schema/mssql-tablecompiler.js +393 -393
  30. package/lib/dialects/mssql/schema/mssql-viewcompiler.js +55 -55
  31. package/lib/dialects/mssql/transaction.js +176 -176
  32. package/lib/dialects/mysql/index.js +317 -317
  33. package/lib/dialects/mysql/query/mysql-querybuilder.js +14 -14
  34. package/lib/dialects/mysql/query/mysql-querycompiler.js +292 -292
  35. package/lib/dialects/mysql/schema/mysql-columncompiler.js +193 -193
  36. package/lib/dialects/mysql/schema/mysql-compiler.js +60 -60
  37. package/lib/dialects/mysql/schema/mysql-tablecompiler.js +426 -426
  38. package/lib/dialects/mysql/schema/mysql-viewbuilder.js +21 -21
  39. package/lib/dialects/mysql/schema/mysql-viewcompiler.js +15 -15
  40. package/lib/dialects/mysql/transaction.js +46 -46
  41. package/lib/dialects/mysql2/index.js +53 -53
  42. package/lib/dialects/mysql2/transaction.js +44 -44
  43. package/lib/dialects/oracle/DEAD_CODE.md +5 -5
  44. package/lib/dialects/oracle/index.js +92 -92
  45. package/lib/dialects/oracle/query/oracle-querycompiler.js +343 -343
  46. package/lib/dialects/oracle/schema/internal/incrementUtils.js +22 -22
  47. package/lib/dialects/oracle/schema/internal/trigger.js +155 -155
  48. package/lib/dialects/oracle/schema/oracle-columnbuilder.js +17 -17
  49. package/lib/dialects/oracle/schema/oracle-columncompiler.js +126 -126
  50. package/lib/dialects/oracle/schema/oracle-compiler.js +124 -124
  51. package/lib/dialects/oracle/schema/oracle-tablecompiler.js +210 -210
  52. package/lib/dialects/oracle/utils.js +107 -107
  53. package/lib/dialects/oracledb/index.js +381 -381
  54. package/lib/dialects/oracledb/query/oracledb-querycompiler.js +481 -481
  55. package/lib/dialects/oracledb/schema/oracledb-columncompiler.js +61 -61
  56. package/lib/dialects/oracledb/schema/oracledb-tablecompiler.js +19 -19
  57. package/lib/dialects/oracledb/schema/oracledb-viewbuilder.js +13 -13
  58. package/lib/dialects/oracledb/schema/oracledb-viewcompiler.js +19 -19
  59. package/lib/dialects/oracledb/transaction.js +98 -98
  60. package/lib/dialects/oracledb/utils.js +208 -208
  61. package/lib/dialects/pgnative/index.js +60 -60
  62. package/lib/dialects/postgres/execution/pg-transaction.js +19 -19
  63. package/lib/dialects/postgres/index.js +373 -373
  64. package/lib/dialects/postgres/query/pg-querybuilder.js +43 -43
  65. package/lib/dialects/postgres/query/pg-querycompiler.js +400 -400
  66. package/lib/dialects/postgres/schema/pg-columncompiler.js +162 -162
  67. package/lib/dialects/postgres/schema/pg-compiler.js +138 -138
  68. package/lib/dialects/postgres/schema/pg-tablecompiler.js +331 -331
  69. package/lib/dialects/postgres/schema/pg-viewbuilder.js +21 -21
  70. package/lib/dialects/postgres/schema/pg-viewcompiler.js +35 -35
  71. package/lib/dialects/redshift/index.js +86 -86
  72. package/lib/dialects/redshift/query/redshift-querycompiler.js +163 -163
  73. package/lib/dialects/redshift/schema/redshift-columnbuilder.js +22 -22
  74. package/lib/dialects/redshift/schema/redshift-columncompiler.js +67 -67
  75. package/lib/dialects/redshift/schema/redshift-compiler.js +14 -14
  76. package/lib/dialects/redshift/schema/redshift-tablecompiler.js +134 -134
  77. package/lib/dialects/redshift/schema/redshift-viewcompiler.js +11 -11
  78. package/lib/dialects/redshift/transaction.js +32 -32
  79. package/lib/dialects/sqlite3/execution/sqlite-transaction.js +172 -172
  80. package/lib/dialects/sqlite3/index.js +263 -263
  81. package/lib/dialects/sqlite3/query/sqlite-querybuilder.js +33 -33
  82. package/lib/dialects/sqlite3/query/sqlite-querycompiler.js +341 -341
  83. package/lib/dialects/sqlite3/schema/ddl.js +380 -380
  84. package/lib/dialects/sqlite3/schema/internal/compiler.js +327 -327
  85. package/lib/dialects/sqlite3/schema/internal/parser-combinator.js +161 -161
  86. package/lib/dialects/sqlite3/schema/internal/parser.js +638 -638
  87. package/lib/dialects/sqlite3/schema/internal/sqlite-ddl-operations.js +41 -41
  88. package/lib/dialects/sqlite3/schema/internal/tokenizer.js +38 -38
  89. package/lib/dialects/sqlite3/schema/internal/utils.js +12 -12
  90. package/lib/dialects/sqlite3/schema/sqlite-columncompiler.js +50 -50
  91. package/lib/dialects/sqlite3/schema/sqlite-compiler.js +80 -80
  92. package/lib/dialects/sqlite3/schema/sqlite-tablecompiler.js +364 -364
  93. package/lib/dialects/sqlite3/schema/sqlite-viewcompiler.js +40 -40
  94. package/lib/execution/batch-insert.js +51 -51
  95. package/lib/execution/internal/delay.js +6 -6
  96. package/lib/execution/internal/ensure-connection-callback.js +41 -41
  97. package/lib/execution/internal/query-executioner.js +62 -62
  98. package/lib/execution/runner.js +325 -325
  99. package/lib/execution/transaction.js +417 -417
  100. package/lib/formatter/formatterUtils.js +42 -42
  101. package/lib/formatter/rawFormatter.js +84 -84
  102. package/lib/formatter/wrappingFormatter.js +253 -253
  103. package/lib/formatter.js +25 -25
  104. package/lib/index.js +3 -3
  105. package/lib/knex-builder/FunctionHelper.js +80 -80
  106. package/lib/knex-builder/Knex.js +59 -59
  107. package/lib/knex-builder/internal/config-resolver.js +57 -57
  108. package/lib/knex-builder/internal/parse-connection.js +87 -87
  109. package/lib/knex-builder/make-knex.js +345 -345
  110. package/lib/logger.js +76 -76
  111. package/lib/migrations/common/MigrationsLoader.js +36 -36
  112. package/lib/migrations/migrate/MigrationGenerator.js +84 -84
  113. package/lib/migrations/migrate/Migrator.js +632 -632
  114. package/lib/migrations/migrate/migrate-stub.js +17 -17
  115. package/lib/migrations/migrate/migration-list-resolver.js +33 -33
  116. package/lib/migrations/migrate/migrator-configuration-merger.js +58 -58
  117. package/lib/migrations/migrate/sources/fs-migrations.js +74 -74
  118. package/lib/migrations/migrate/stub/cjs.stub +15 -15
  119. package/lib/migrations/migrate/stub/coffee.stub +13 -13
  120. package/lib/migrations/migrate/stub/eg.stub +14 -14
  121. package/lib/migrations/migrate/stub/js-schema.stub +22 -22
  122. package/lib/migrations/migrate/stub/js.stub +22 -22
  123. package/lib/migrations/migrate/stub/knexfile-coffee.stub +34 -34
  124. package/lib/migrations/migrate/stub/knexfile-eg.stub +43 -43
  125. package/lib/migrations/migrate/stub/knexfile-js.stub +47 -47
  126. package/lib/migrations/migrate/stub/knexfile-ls.stub +35 -35
  127. package/lib/migrations/migrate/stub/knexfile-ts.stub +47 -47
  128. package/lib/migrations/migrate/stub/ls.stub +14 -14
  129. package/lib/migrations/migrate/stub/mjs.stub +23 -23
  130. package/lib/migrations/migrate/stub/ts-schema.stub +21 -21
  131. package/lib/migrations/migrate/stub/ts.stub +21 -21
  132. package/lib/migrations/migrate/table-creator.js +77 -77
  133. package/lib/migrations/migrate/table-resolver.js +27 -27
  134. package/lib/migrations/seed/Seeder.js +137 -137
  135. package/lib/migrations/seed/seed-stub.js +13 -13
  136. package/lib/migrations/seed/seeder-configuration-merger.js +60 -60
  137. package/lib/migrations/seed/sources/fs-seeds.js +65 -65
  138. package/lib/migrations/seed/stub/coffee.stub +9 -9
  139. package/lib/migrations/seed/stub/eg.stub +11 -11
  140. package/lib/migrations/seed/stub/js.stub +13 -13
  141. package/lib/migrations/seed/stub/ls.stub +11 -11
  142. package/lib/migrations/seed/stub/mjs.stub +12 -12
  143. package/lib/migrations/seed/stub/ts.stub +13 -13
  144. package/lib/migrations/util/fs.js +86 -86
  145. package/lib/migrations/util/import-file.js +12 -12
  146. package/lib/migrations/util/is-module-type.js +9 -9
  147. package/lib/migrations/util/template.js +52 -52
  148. package/lib/migrations/util/timestamp.js +14 -14
  149. package/lib/query/analytic.js +52 -52
  150. package/lib/query/constants.js +15 -15
  151. package/lib/query/joinclause.js +270 -270
  152. package/lib/query/method-constants.js +136 -136
  153. package/lib/query/querybuilder.js +1793 -1793
  154. package/lib/query/querycompiler.js +1634 -1634
  155. package/lib/raw.js +139 -139
  156. package/lib/ref.js +39 -39
  157. package/lib/schema/builder.js +115 -115
  158. package/lib/schema/columnbuilder.js +146 -146
  159. package/lib/schema/columncompiler.js +307 -307
  160. package/lib/schema/compiler.js +187 -187
  161. package/lib/schema/internal/helpers.js +55 -55
  162. package/lib/schema/tablebuilder.js +379 -379
  163. package/lib/schema/tablecompiler.js +450 -450
  164. package/lib/schema/viewbuilder.js +92 -92
  165. package/lib/schema/viewcompiler.js +138 -138
  166. package/lib/util/finally-mixin.js +13 -13
  167. package/lib/util/helpers.js +95 -95
  168. package/lib/util/is.js +32 -32
  169. package/lib/util/nanoid.js +40 -40
  170. package/lib/util/noop.js +1 -1
  171. package/lib/util/save-async-stack.js +14 -14
  172. package/lib/util/security.js +32 -32
  173. package/lib/util/string.js +190 -190
  174. package/lib/util/timeout.js +29 -29
  175. package/package.json +294 -296
  176. package/scripts/act-testing/act.sh +19 -19
  177. package/scripts/act-testing/merged-no-label.json +11 -11
  178. package/scripts/act-testing/merged-patch-labeled.json +12 -12
  179. package/scripts/act-testing/merged-skip-labeled.json +12 -12
  180. package/scripts/act-testing/not-merged-patch-labeled.json +12 -12
  181. package/scripts/build-for-release.sh +121 -121
  182. package/scripts/build.js +125 -125
  183. package/scripts/clean.js +31 -31
  184. package/scripts/docker-compose.yml +150 -150
  185. package/scripts/format-changelog.js +55 -55
  186. package/scripts/next-release-howto.md +24 -24
  187. package/scripts/oracledb-install-driver-libs.sh +82 -82
  188. package/scripts/release.sh +36 -36
  189. package/scripts/runkit-example.js +35 -35
  190. package/scripts/stress-test/README.txt +18 -18
  191. package/scripts/stress-test/docker-compose.yml +55 -55
  192. package/scripts/stress-test/knex-stress-test.js +212 -212
  193. package/scripts/stress-test/mysql2-random-hanging-every-now-and-then.js +149 -149
  194. package/scripts/stress-test/mysql2-sudden-exit-without-error.js +101 -101
  195. package/scripts/stress-test/reconnect-test-mysql-based-drivers.js +188 -188
  196. package/types/index.d.mts +11 -0
  197. package/types/index.d.ts +3321 -3321
  198. package/types/result.d.ts +27 -27
  199. package/types/tables.d.ts +4 -4
package/CONTRIBUTING.md CHANGED
@@ -1,190 +1,190 @@
1
- ## How to contribute to Knex.js
2
-
3
- - Make changes in the `/lib` directory.
4
-
5
- - Before sending a pull request for a feature or bug fix, be sure to have
6
- [tests](https://github.com/knex/knex/tree/master/test). Every pull request that changes the queries should have
7
- also **integration tests which are ran against real database** (in addition to unit tests which checks which kind of queries
8
- are being created).
9
-
10
- - Use the same coding style as the rest of the
11
- [codebase](https://github.com/knex/knex/blob/master/knex.js).
12
-
13
- - All pull requests should be made to the `master` branch.
14
-
15
- - Pull request description should have link to corresponding PR of documentation branch.
16
-
17
- - All pull requests that modify the public API should be updated in [types/index.d.ts](https://github.com/knex/knex/blob/master/types/index.d.ts)
18
-
19
- ## Documentation
20
-
21
- Documentation is maintained in the `/docs` folder. every pull request that changes the public API should also update the docs
22
-
23
- ## I would like to add support for new dialect to knex, is it possible?
24
-
25
- Currently there are already way too many dialects supported in `knex` and instead of adding new dialect to central codebase, all the dialects should be moved to separate npm packages out from `knex` core library with their respective maintainers and test suites.
26
-
27
- So if you like to write your own dialect, you can just inherit own dialect from knex base classes and use it by passing dialect to knex in knex configuration (https://runkit.com/embed/90b3cpyr4jh2):
28
-
29
- ```js
30
- // simple dialect overriding sqlite3 dialect to use sqlite3-offline driver
31
- require('sqlite3-offline');
32
- const Knex = require('knex');
33
-
34
- const Dialect = require(`knex/lib/dialects/sqlite3/index.js`);
35
- Dialect.prototype._driver = () => require('sqlite3-offline');
36
-
37
- const knex = Knex({
38
- client: Dialect,
39
- connection: ':memory:',
40
- });
41
-
42
- console.log(knex.select(knex.raw(1)).toSQL());
43
-
44
- await knex.schema.createTable('fooobar', (t) => {
45
- t.bigincrements('id');
46
- t.string('data');
47
- });
48
- await knex('fooobar').insert({ data: 'nomnom' });
49
-
50
- console.log('Gimme all the data:', await knex('fooobar'));
51
- ```
52
-
53
- ## What is minimal code to reproduce bug and why I have to provide that when I can just tell whats the problem is
54
-
55
- Writing minimal reproduction code for the problem is time-consuming and sometimes it is also really hard, for
56
- example when the original code where the bug happens is written using express or mocha. So why is it necessary
57
- for me to commit so much time to it when the problem is in `knex`? Contributors should be grateful that I reported
58
- the bug I found.
59
-
60
- The point of runnable code to reproduce the problem is to easily verify that there really is a problem and that the one
61
- who did the report did nothing wrong (surprisingly often problem is in the user code). So instead of just description
62
- what to do the complete code encourages devs to actually test out that problem exists and start solving it and it
63
- saves lots of time.
64
-
65
- tl;dr list:
66
-
67
- 1. Actually in most of the cases developer already figures out what was the problem when writing the minimal test case
68
- or if there was problem how stuff was initialized or how async code was written it is easy to point out the problem.
69
-
70
- 2. It motivates developer to actually try out if the bug really exist by not having to figure out from incomplete example
71
- environment in which and how bug actually manifests.
72
-
73
- 3. There are currently very few people fixing knex issues and if one has to put easily 15-30 minutes time to issue just
74
- to see that I cannot reproduce this issue it just wastes development hours that were available for improving knex.
75
-
76
- Test case should initialize needed tables, insert needed data and fail...
77
-
78
- ```js
79
- const knex = require('knex')({
80
- client: 'pg',
81
- connection: 'postgres:///knex_test'
82
- });
83
-
84
- async function main() {
85
- await knex.schema.createTable(...);
86
- await knex('table').insert({foo: 'bar}');
87
- await knex.destroy();
88
- }
89
-
90
- main();
91
- ```
92
-
93
- Usually issues without reproduction code available are just closed and if the same issue is reported multiple
94
- times maybe someone looks into it.
95
-
96
- One easy way to setup database for your reproduction is to use database from knex's docker compose setup (npm run db:start) and by checking the connection settings from tests' `test/knexfile.js`.
97
-
98
- ## Integration Tests
99
-
100
- ### The Easy Way
101
-
102
- By default, Knex runs tests against sqlite3, postgresql, mysql, mysql2, mssql and oracledb drivers. All databases can be initialized and ran with docker.
103
-
104
- Docker databases can be started and initialized with:
105
-
106
- ```bash
107
- npm run db:start
108
- ```
109
-
110
- and stopped with:
111
-
112
- ```bash
113
- npm run db:stop
114
- ```
115
-
116
- In case you don't need all of the databases, you can use simplified dev Docker configuration that only runs PostgreSQL, by running `npm run db:start:postgres` and `npm run db:stop:postgres` accordingly.
117
-
118
- ### Installing support for oracledb
119
-
120
- Oracle has started providing precompiled driver libs for all the platforms, which makes it viable to run oracle tests also locally against oracledb running in docker.
121
-
122
- Check message when running
123
-
124
- ```bash
125
- npm install oracledb
126
- ```
127
-
128
- and download driver library binary packages and unzip it to ~/lib directory.
129
-
130
- ### Specifying Databases
131
-
132
- You can optionally specify which dialects to test using the `DB` environment variable. Values should be space separated and can include:
133
-
134
- - mysql
135
- - mysql2
136
- - postgres
137
- - sqlite3
138
- - oracledb
139
- - mssql
140
-
141
- ```bash
142
- $ DB='postgres mysql' npm test
143
- ```
144
-
145
- ### Custom Configuration
146
-
147
- If you'd like to override the database configuration (to use a different host, for example), you can override the path to the [default test configuration](https://github.com/knex/knex/blob/master/test/knexfile.js) using the `KNEX_TEST` environment variable.
148
-
149
- ```bash
150
- $ KNEX_TEST='./path/to/my/config.js' npm test
151
- ```
152
-
153
- ### Creating Postgres User
154
-
155
- If you are running tests against own local database one might need to setup test user and database for knex to connect.
156
-
157
- To create a new user, login to Postgres and use the following queries to add the user. This assumes you've already created the `knex_test` database.
158
-
159
- ```
160
- CREATE ROLE postgres WITH LOGIN PASSWORD '';
161
- GRANT ALL PRIVILEGES ON DATABASE "knex_test" TO postgres;
162
- ```
163
-
164
- Once this is done, check it works by attempting to login:
165
-
166
- ```
167
- psql -h localhost -U postgres -d knex_test
168
- ```
169
-
170
- ## Typescript source files
171
-
172
- > TL;DR: Starting with release 2.0.0 Knex is adding support for Typescript source files. Thus to develop in this repo you will need to run `npm run build` each time you edit `.ts` files to generate the resulting `.js` files. This is automatically run whenever you run `npm install` or checkout a new Git branch so when developing in Javascript you don't have to worry about it. It is encouraged that new functionality and sources be written in Typescript but this is not required.
173
-
174
- Starting with release 2.0.0, Knex is support source additions in Typescript! This allows for better safety in the code added. However, pre-2.0.0 Knex was always written in pure Javascript and thus a "hybrid" approach is being used for 2.0.0 to allow for the new `.ts` files to exist along `.js` files that make up the majority of this repository.
175
-
176
- To develop in this repository use the `npm run build` and `npm run clean` commands to compile and delete the `.js` and related files from `.ts` files. If you wish to have the `tsc` compiled watch and recompile on changes then run `npm run build:ts -- --watch`. Note that for easy integration with Javascript the outputted files are done in a "side-by-side" manner meaning that `lib/foo/bar.ts` will result in `lib/foo/bar.js`. This is done automatically via the npm script command `"prepare"` whenever you run `npm install` and Git hook for `post-checkout` (added by Husky) which executes when you run commands like `git checkout` , thus making it easier to not have to worry about this if you're working in pure Javascript.
177
-
178
- ## Want to be Collaborator?
179
-
180
- There is always room for more collaborators. Be active on resolving github issues / sending pull requests / reviewing code and we will ask you to join.
181
-
182
- ### Etiquette (/ˈɛtᵻkɛt/ or /ˈɛtᵻkɪt/, French: [e.ti.kɛt])
183
-
184
- Make pull requests for your changes, do not commit directly to master (release stuff like fixing changelog are ok though).
185
-
186
- All the pull requests must be peer reviewed by other collaborator, so don't merge your request before that. If there is no response ping others.
187
-
188
- If you are going to add new feature to knex (not just a bugfix) it should be discussed first with others to agree on details.
189
-
190
- Join Gitter chat if you feel to chat outside of github issues.
1
+ ## How to contribute to Knex.js
2
+
3
+ - Make changes in the `/lib` directory.
4
+
5
+ - Before sending a pull request for a feature or bug fix, be sure to have
6
+ [tests](https://github.com/knex/knex/tree/master/test). Every pull request that changes the queries should have
7
+ also **integration tests which are ran against real database** (in addition to unit tests which checks which kind of queries
8
+ are being created).
9
+
10
+ - Use the same coding style as the rest of the
11
+ [codebase](https://github.com/knex/knex/blob/master/knex.js).
12
+
13
+ - All pull requests should be made to the `master` branch.
14
+
15
+ - Pull request description should have link to corresponding PR of documentation branch.
16
+
17
+ - All pull requests that modify the public API should be updated in [types/index.d.ts](https://github.com/knex/knex/blob/master/types/index.d.ts)
18
+
19
+ ## Documentation
20
+
21
+ Documentation is maintained in the `/docs` folder. every pull request that changes the public API should also update the docs
22
+
23
+ ## I would like to add support for new dialect to knex, is it possible?
24
+
25
+ Currently there are already way too many dialects supported in `knex` and instead of adding new dialect to central codebase, all the dialects should be moved to separate npm packages out from `knex` core library with their respective maintainers and test suites.
26
+
27
+ So if you like to write your own dialect, you can just inherit own dialect from knex base classes and use it by passing dialect to knex in knex configuration (https://runkit.com/embed/90b3cpyr4jh2):
28
+
29
+ ```js
30
+ // simple dialect overriding sqlite3 dialect to use sqlite3-offline driver
31
+ require('sqlite3-offline');
32
+ const Knex = require('knex');
33
+
34
+ const Dialect = require(`knex/lib/dialects/sqlite3/index.js`);
35
+ Dialect.prototype._driver = () => require('sqlite3-offline');
36
+
37
+ const knex = Knex({
38
+ client: Dialect,
39
+ connection: ':memory:',
40
+ });
41
+
42
+ console.log(knex.select(knex.raw(1)).toSQL());
43
+
44
+ await knex.schema.createTable('fooobar', (t) => {
45
+ t.bigincrements('id');
46
+ t.string('data');
47
+ });
48
+ await knex('fooobar').insert({ data: 'nomnom' });
49
+
50
+ console.log('Gimme all the data:', await knex('fooobar'));
51
+ ```
52
+
53
+ ## What is minimal code to reproduce bug and why I have to provide that when I can just tell whats the problem is
54
+
55
+ Writing minimal reproduction code for the problem is time-consuming and sometimes it is also really hard, for
56
+ example when the original code where the bug happens is written using express or mocha. So why is it necessary
57
+ for me to commit so much time to it when the problem is in `knex`? Contributors should be grateful that I reported
58
+ the bug I found.
59
+
60
+ The point of runnable code to reproduce the problem is to easily verify that there really is a problem and that the one
61
+ who did the report did nothing wrong (surprisingly often problem is in the user code). So instead of just description
62
+ what to do the complete code encourages devs to actually test out that problem exists and start solving it and it
63
+ saves lots of time.
64
+
65
+ tl;dr list:
66
+
67
+ 1. Actually in most of the cases developer already figures out what was the problem when writing the minimal test case
68
+ or if there was problem how stuff was initialized or how async code was written it is easy to point out the problem.
69
+
70
+ 2. It motivates developer to actually try out if the bug really exist by not having to figure out from incomplete example
71
+ environment in which and how bug actually manifests.
72
+
73
+ 3. There are currently very few people fixing knex issues and if one has to put easily 15-30 minutes time to issue just
74
+ to see that I cannot reproduce this issue it just wastes development hours that were available for improving knex.
75
+
76
+ Test case should initialize needed tables, insert needed data and fail...
77
+
78
+ ```js
79
+ const knex = require('knex')({
80
+ client: 'pg',
81
+ connection: 'postgres:///knex_test'
82
+ });
83
+
84
+ async function main() {
85
+ await knex.schema.createTable(...);
86
+ await knex('table').insert({foo: 'bar}');
87
+ await knex.destroy();
88
+ }
89
+
90
+ main();
91
+ ```
92
+
93
+ Usually issues without reproduction code available are just closed and if the same issue is reported multiple
94
+ times maybe someone looks into it.
95
+
96
+ One easy way to setup database for your reproduction is to use database from knex's docker compose setup (npm run db:start) and by checking the connection settings from tests' `test/knexfile.js`.
97
+
98
+ ## Integration Tests
99
+
100
+ ### The Easy Way
101
+
102
+ By default, Knex runs tests against sqlite3, postgresql, mysql, mysql2, mssql and oracledb drivers. All databases can be initialized and ran with docker.
103
+
104
+ Docker databases can be started and initialized with:
105
+
106
+ ```bash
107
+ npm run db:start
108
+ ```
109
+
110
+ and stopped with:
111
+
112
+ ```bash
113
+ npm run db:stop
114
+ ```
115
+
116
+ In case you don't need all of the databases, you can use simplified dev Docker configuration that only runs PostgreSQL, by running `npm run db:start:postgres` and `npm run db:stop:postgres` accordingly.
117
+
118
+ ### Installing support for oracledb
119
+
120
+ Oracle has started providing precompiled driver libs for all the platforms, which makes it viable to run oracle tests also locally against oracledb running in docker.
121
+
122
+ Check message when running
123
+
124
+ ```bash
125
+ npm install oracledb
126
+ ```
127
+
128
+ and download driver library binary packages and unzip it to ~/lib directory.
129
+
130
+ ### Specifying Databases
131
+
132
+ You can optionally specify which dialects to test using the `DB` environment variable. Values should be space separated and can include:
133
+
134
+ - mysql
135
+ - mysql2
136
+ - postgres
137
+ - sqlite3
138
+ - oracledb
139
+ - mssql
140
+
141
+ ```bash
142
+ $ DB='postgres mysql' npm test
143
+ ```
144
+
145
+ ### Custom Configuration
146
+
147
+ If you'd like to override the database configuration (to use a different host, for example), you can override the path to the [default test configuration](https://github.com/knex/knex/blob/master/test/knexfile.js) using the `KNEX_TEST` environment variable.
148
+
149
+ ```bash
150
+ $ KNEX_TEST='./path/to/my/config.js' npm test
151
+ ```
152
+
153
+ ### Creating Postgres User
154
+
155
+ If you are running tests against own local database one might need to setup test user and database for knex to connect.
156
+
157
+ To create a new user, login to Postgres and use the following queries to add the user. This assumes you've already created the `knex_test` database.
158
+
159
+ ```
160
+ CREATE ROLE postgres WITH LOGIN PASSWORD '';
161
+ GRANT ALL PRIVILEGES ON DATABASE "knex_test" TO postgres;
162
+ ```
163
+
164
+ Once this is done, check it works by attempting to login:
165
+
166
+ ```
167
+ psql -h localhost -U postgres -d knex_test
168
+ ```
169
+
170
+ ## Typescript source files
171
+
172
+ > TL;DR: Starting with release 2.0.0 Knex is adding support for Typescript source files. Thus to develop in this repo you will need to run `npm run build` each time you edit `.ts` files to generate the resulting `.js` files. This is automatically run whenever you run `npm install` or checkout a new Git branch so when developing in Javascript you don't have to worry about it. It is encouraged that new functionality and sources be written in Typescript but this is not required.
173
+
174
+ Starting with release 2.0.0, Knex is support source additions in Typescript! This allows for better safety in the code added. However, pre-2.0.0 Knex was always written in pure Javascript and thus a "hybrid" approach is being used for 2.0.0 to allow for the new `.ts` files to exist along `.js` files that make up the majority of this repository.
175
+
176
+ To develop in this repository use the `npm run build` and `npm run clean` commands to compile and delete the `.js` and related files from `.ts` files. If you wish to have the `tsc` compiled watch and recompile on changes then run `npm run build:ts -- --watch`. Note that for easy integration with Javascript the outputted files are done in a "side-by-side" manner meaning that `lib/foo/bar.ts` will result in `lib/foo/bar.js`. This is done automatically via the npm script command `"prepare"` whenever you run `npm install` and Git hook for `post-checkout` (added by Husky) which executes when you run commands like `git checkout` , thus making it easier to not have to worry about this if you're working in pure Javascript.
177
+
178
+ ## Want to be Collaborator?
179
+
180
+ There is always room for more collaborators. Be active on resolving github issues / sending pull requests / reviewing code and we will ask you to join.
181
+
182
+ ### Etiquette (/ˈɛtᵻkɛt/ or /ˈɛtᵻkɪt/, French: [e.ti.kɛt])
183
+
184
+ Make pull requests for your changes, do not commit directly to master (release stuff like fixing changelog are ok though).
185
+
186
+ All the pull requests must be peer reviewed by other collaborator, so don't merge your request before that. If there is no response ping others.
187
+
188
+ If you are going to add new feature to knex (not just a bugfix) it should be discussed first with others to agree on details.
189
+
190
+ Join Gitter chat if you feel to chat outside of github issues.
package/LICENSE CHANGED
@@ -1,22 +1,22 @@
1
- Copyright (c) 2013-present Tim Griesser
2
-
3
- Permission is hereby granted, free of charge, to any person
4
- obtaining a copy of this software and associated documentation
5
- files (the "Software"), to deal in the Software without
6
- restriction, including without limitation the rights to use,
7
- copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the
9
- Software is furnished to do so, subject to the following
10
- conditions:
11
-
12
- The above copyright notice and this permission notice shall be
13
- included in all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
- OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2013-present Tim Griesser
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.