833 Commits

Author SHA1 Message Date
Igor Savin
a01c35941a Refactor migrator (#2695)
* Refactor migrator

* Fix exports

* Fix ESLint

* Fix migrator

* Fix reference to config

* Split some more

* Fix table builder

* Fix argument order

* Merge branch 'master' of https://github.com/tgriesser/knex into feature/2690-support-multiple-migration-dirs

# Conflicts:
#	src/migrate/index.js
#	test/index.js
#	test/unit/migrate/migrator.js
2018-07-17 10:41:44 +03:00
Simon Lidén
0f4c9bdef9 Fix issue with select(0) (#2711)
* Fix issue with select(0). Fixes #2658
2018-07-13 09:31:53 -04:00
Fabian Kantereit
e08c14b7b1 Implement missing schema support for mssql dialect 2018-07-10 12:55:12 -04:00
Tim Griesser
232fe9f151
Add Prettier (#2697)
* Add prettier
* Run files through prettier
2018-07-09 08:10:34 -04:00
Mikael Lepistö
cb3a85e738
Normalized and validated driverNames of test db clients and fixed oracle test setup (#2692)
* Normalized and validated driverNames of test db clients and fixed oracle test setup

* Fixed failed queries from old query building tests which hadn't been ran in ages

* Allow selecting node version which is used to run oracledb docker tests

* Improved sql tester error messages

* Fixed rest of the oracledb tests

* Removed invalid flag from docker-compose

* Print mssql logs if initialization fails

* Fixed syntax error + final tests

* Added restart of failure for mssql DB initialization to try again if server was not ready

* Printout always mssql logs after container is started

* Fixed wait time printing after trying to connect

* Use npm run oracledb:test for testing oracle in travis
2018-07-08 14:10:51 +03:00
Igor Savin
3282d6a890 chore: Update dependencies. Remove estraverse (#2691)
* Update dependencies. Remove estraverse

* Fix compatibility with new Sinon

* Increase mssql timeout
2018-07-07 10:47:51 +03:00
Pablo M
a41316bb34 Fix knex.initialize() and adds test (#2477)
* Fix knex.initialize() and adds test

* Fix knex.initialize() and adds test

* Added test for reinitializing pool after destroy

* Fixed destroy / reinitialization test

* Fixed the fix
2018-07-02 23:52:32 +03:00
Mikael Lepistö
e2f617b968
Drop mariadb support (#2681)
* Dropped support for mariasql

* ESLint
2018-07-01 23:06:26 +03:00
Mikael Lepistö
b349ac4a8c
Various fixes to mssql dialect (#2653)
* Fixed float type of mssql to be float

* Many tests where postgres test was not actually ran at all

* Migrations to be mssql compatible

Mssql driver doesn't handle if multiple queries are sent to same transaction concurrently.

* Prevented mssql failing when invalid schema builder was executed by accident

Instead of trying to generate sql from broken schema calls, just make exception to leak before query compiling is started

* Fixed mssql trx rollback to always throw an error

Also modified some connection test query to be mssql compatible

* Fixed various bugs from MSSQL driver to make tests run

* Fixed mssql unique index to be compatible with other dialect implementations

* Enable running mssql tests on CI

* Test for #2588

* Updated tests to not be dependend on tables left from previous test rans

* Trying to make mssql server work on travis
2018-06-29 10:47:06 +03:00
Facundo Matteo
ec8550249f Make the stream catch errors in the query (#2638)
* Make the stream catch errors in the query

* Fix another case in which stream doesnt emits error

* Linter stuff

* Remove setTimeout in tests

* Make a test not to check the MySQL error code

* Fix stream error catching for MariaDB and PostgreSQL

* Fix stream error catching in Oracle

* Throw the error after emitting it to the stream

* Throw the error without instantiating a new Error
2018-06-27 22:42:50 +03:00
Sami Koskimäki
1c65e69bc0 fixes 2630 (#2642) 2018-06-05 15:31:09 +03:00
Igor Savin
d9cd54b2ac Remove readable-stream and safe-buffer (#2640)
* Add json support to the query builder for mysql

refs #1036

Based on #1902

* Clarify supported version

* Use native Buffer and Stream implementations
2018-06-01 14:34:27 +03:00
Tim
3e95405037 fix wrapIdentifier not being called in postgres alter column (#2612)
* fix wrapIdentifier not being called in postgres alter column

* add test for wrapIdentifier call in postgres alter column

* add comment regarding issue

* add issue & PR #'s in comment
2018-05-30 17:57:51 +03:00
Igor Savin
4d4e4ca1e7 Add json support to the query builder for mysql (#2635)
* Add json support to the query builder for mysql

refs #1036

Based on #1902

* Clarify supported version
2018-05-30 17:26:03 +03:00
Simon Lidén
05e9150346 Drop support for strong-oracle (#2487) 2018-05-29 13:31:40 -04:00
Michael Storgaard
51ee9bba17 Fixed onIn with empty values array (#2513) 2018-05-29 12:35:37 -04:00
Simon Lidén
65509c38ef Allow overwriting log functions (#2625)
* Example build of custom log functions
* Handle logger object better for transactions
* Adjust test to ignore sqlite warning message
2018-05-29 11:42:03 -04:00
Will
7a60e310c8 Add support for native enums on Postgres (#2632)
Reference https://www.postgresql.org/docs/current/static/sql-createtype.html

Closes #394

Signed-off-by: Will Soto <will.soto9@gmail.com>
2018-05-29 10:09:13 -04:00
Michael Oliver
db390b11e6 Increment floats (#2614)
* Fix increment/decrement with float values

* parse float in mariadb

* mysql produces float(8, 2), not double
2018-05-19 11:49:00 +03:00
Andy Stanberry
51e44052b4 Support postgresql connection uri protocol (#2609) 2018-05-18 12:12:15 +03:00
Simon Lidén
e724066fcb Added 'ref' function (#2509)
* Added 'ref' function

* Fixed Ref export

* Added .as() for aliasing references
2018-05-02 13:31:16 +03:00
Jiri Spac
e086427db0 fixes #2500 (#2505) 2018-04-26 00:11:24 +03:00
Ricardo Graça
14ac2cbaa7 Create timestamp columns with millisecond precision on MySQL 5.6 and newer (#2542)
* Add test for precise timestamps schema building

* Create precise timestamp columns on MySQL 5.6+

* Increase precision of timestamps to microsecond

- Six is the maximum that it supports and there's no reason not to use
the maximum available precision.

* Add warning when version is not specified in MySQL

* Update warning message when missing mysql version
2018-04-18 23:14:29 +03:00
Simon Lidén
8488e22abe
Bugfix/query event sql string (#2566)
* Restore 'query' event to its original form (no native sql string). Fixes #2549

* Fix assertions in test
2018-04-12 09:17:45 +02:00
Mikael Lepistö
c89119b681 Fixed running tape tests when DB variable not set 2018-04-08 22:27:33 +03:00
Adam Cofer
ee8cc35ecb Fix #2545, bring redshift wrapIdentifier custom hook up to date with postgres (#2551)
* Add a Redshift dialect that inherits from Postgres.

* Turn .index() and .dropIndex() into no-ops with warnings in the Redshift dialect.

* Update the Redshift dialect to be compatible with master.

* Update package.json

* Disable liftoff cli

* Remove the CLI

* Add lib to the repo

* Allow the escaping of named bindings.

* Update dist

* Update the Redshift dialect’s instantiation of the query and column compilers.

* Update the distribution

* Fix a merge conflict

* Take lib back out

* Trying to bring back in line with tgreisser/knex

* Add npm 5 package-lock

* Bring cli.js back in line

* Bring cli.js back in line

* Progress commit on redshift integration tests

* Revert "Progress commit on redshift integration tests"

This reverts commit 207e31635c638853dec54ce0580d34559ba5a54c.

* Progress commit

* Working not null on primary columns in createTable

* Working redshift unit tests

* Working unit and integration tests, still need to fix migration tests

* Brought datatypes more in line with what redshift actually supports

* Added query compiler unit tests

* Add a hacky returning clause for redshift ugh

* Working migration integration tests

* Working insert integration tests

* Allow multiple insert returning values

* Working select integration tests

* Working join integration tests

* Working aggregate integration tests

* All integration suite tests working

* Put docker index for reconnect tests back

* Redshift does not support insert...returning, there does not seem to be a way around that, therefore accept it and test accordingly

* Leave redshift integration tests in place, but do not run them by default

* Fix mysql order by test

* Fix more tests

* Change test db name to knex_test for consistency

* Address PR comments

* Sublime Text gitignore

* Redshift does not support adding more than one column in alter table

* Fix integration tests for redshift

* Linter

* Combine dialect test skip if clause
2018-04-05 01:43:39 +03:00
Igor Savin
843a16799d Support DB schema for migrations - fixes #2499 (#2559)
* WIP

* implement schema support for migrations

* Refactor

* Cleanup

* Restore unneeded changes

* Restore more removed code

* Restore newline

* Execute all tests

* Fix linting error

* Add schema creation

* Drop tables before dropping schema

* Cascade drop for schema
2018-04-05 01:19:08 +03:00
Randy Garces
a85b3a4fa0 GH-2550 Add support to wrap returning column (#2554)
* GH-2550 Add support to wrap returning column

- utilize `this.formatter.wrap` for every columnName in returningClause

* #2550  Add unit test

* Fix unit test
2018-04-05 00:36:38 +03:00
Julien Bouquillon
0a1976d8fd add clearOrder method fix #2360 (#2553) 2018-04-02 17:28:01 +03:00
Joel Mukuthu
fbef9fcec7 feat: countDistinct with multiple columns (#2449)
* test(QueryBuilder): add test for countDistinct with multiple columns

* test: add integration test for countDistinct with multiple columns

* feat(QueryBuilder): support multiple columns for countDistinct

* feat(QueryBuilder): support object alias notation for aggregate methods

i.e. `count`, `countDistinct`, `max`, `min`, `avg`, `avgDistinct`, `sum`, `sumDistinct`

* test: fix integration tests for countDistinct

* fix(QueryBuilder): fix countDistinct formatting with multiple columns

* refactor(QueryBuilder): add _aggregate from helpers

* fix(QueryCompiler): only use parens for distinct with postgres

* test(QueryBuilder): remove unsupported tests

for count with multiple distinct columns in databases where this is
not supported

* refactor(QueryBuilder): improve readability
2018-03-12 23:42:43 +02:00
Simon Lidén
ad1062b905
Added error if chaining update/insert/etc with first() (#2506) 2018-02-22 12:33:55 +01:00
Rhys van der Waerden
965542d3ef Support multi-column whereIn with query (#1390)
* Support multi-column `whereIn` with query

Add support for supplying a subquery for a `whereIn` statment on multiple columns.

Fixes #1384.

* Fixed method

* Removed duplicate import

* Fixed isArray calls and linter warnings

* Fixed isArray call

* Fixed tests and added assertions for all dialects
2018-02-21 22:51:09 +02:00
Simon Lidén
397104c3dc
Added knexTxId to query events and debug calls (#2476)
* Added knexTxId to query events and debug calls

* Added __knexTxId to oracle transactions

* Set knexTxId also in oracledb
2018-02-21 13:26:59 +01:00
Mikael Lepistö
ce0946e74b
Runnin mssql tests in docker (#2496)
* Run SQL Server tests locally running SQL server in docker

* Made oracledb test script naming consistent with mssql

* Updated documentation with more info about oracledb and mssql testing
2018-02-20 11:51:51 +02:00
nico
522ccba8f7 Checks for an empty, undefined or null object on transacting (#2494)
* Checks for an empty, undefined or null object on transacting

Fixes https://github.com/tgriesser/knex/issues/2079

Those values indicates that the developer probably made a mistake.

* Fix message assertions
2018-02-20 11:41:21 +02:00
Mikael Lepistö
ece2da12ca
Added npm run test:oracledb command that runs oracledb tests in docker (#2491)
Also cleaned up some old docker configurations from test knexfile
2018-02-20 10:47:05 +02:00
Simon Lidén
ec75f02432
Added test for Event 'start' (#2488)
* Added test for Event 'start'

* Typecast to string
2018-02-19 10:13:10 +01:00
Simon Lidén
074ceaeadd
Allow calling lock procedures (such as forUpdate) outside of transaction. Fixes #2403. (#2475) 2018-02-16 14:06:49 +01:00
Mikael Lepistö
d4a85db410
Removed old docker tests, new stress test setup tests are testing the same stuff (#2474)
Currently stress tests are run locally manually, but CI could be set up to run them for a few minutes and record request counts and memory usage during tests.
2018-02-16 13:13:04 +02:00
wubzz
543e92fc1f
Throw an error if .update() results in an empty sql (#2472)
* Throw an error if .update() results in an empty sql

* Indentation
2018-02-15 13:28:35 +01:00
Sami Koskimäki
8771bd4781 Use tarn as pool (#2450)
* replace generic-pool with Tarn

* fix bug where mariadb client didn't propagate connection errors to pool

* destroy connection if a query times out (and cancellation is not enabled)

Before this change, when a query timeout happened without { cancel: true }
the connection was immediately released back to the pool. If the query
timed out because of a time consuming query, the released connection would
still execute the query to its end and the connection would be useless until
that time. This commit marks the connection as disposed so that the pool never
again gives that connection to anyone, and destorys it in the near future.

* fix a weird database version dependent casing bug in a tests

* fix an unstable test that failed randomly because the query order was not guaranteed
2018-02-07 11:17:17 +02:00
Adam Cofer
5f81e8aeb9 Add redshift support without changing cli or package.json (#2233)
* Add a Redshift dialect that inherits from Postgres.

* Turn .index() and .dropIndex() into no-ops with warnings in the Redshift dialect.

* Update the Redshift dialect to be compatible with master.

* Update package.json

* Disable liftoff cli

* Remove the CLI

* Add lib to the repo

* Allow the escaping of named bindings.

* Update dist

* Update the Redshift dialect’s instantiation of the query and column compilers.

* Update the distribution

* Fix a merge conflict

* Take lib back out

* Trying to bring back in line with tgreisser/knex

* Add npm 5 package-lock

* Bring cli.js back in line

* Bring cli.js back in line

* Progress commit on redshift integration tests

* Revert "Progress commit on redshift integration tests"

This reverts commit 207e31635c638853dec54ce0580d34559ba5a54c.

* Progress commit

* Working not null on primary columns in createTable

* Working redshift unit tests

* Working unit and integration tests, still need to fix migration tests

* Brought datatypes more in line with what redshift actually supports

* Added query compiler unit tests

* Add a hacky returning clause for redshift ugh

* Working migration integration tests

* Working insert integration tests

* Allow multiple insert returning values

* Working select integration tests

* Working join integration tests

* Working aggregate integration tests

* All integration suite tests working

* Put docker index for reconnect tests back

* Redshift does not support insert...returning, there does not seem to be a way around that, therefore accept it and test accordingly

* Leave redshift integration tests in place, but do not run them by default

* Fix mysql order by test

* Fix more tests

* Change test db name to knex_test for consistency

* Address PR comments
2018-02-03 15:33:02 +02:00
Joel Mukuthu
bf1fa63118 Add queryContext to schema and query builders (#2314)
* feat(query-builder): add hookContext for wrapIdentifier

* refactor: use isUndefined

* test(transaction): test passing of hookContext

* feat(runnner): pass context to postProcessResponse

* test(runner): test postProcessResponse for raw responses

* test(raw): test passing of hookContext

* feat: add hookContext to Raw and SchemaBuilder

* test(transaction): fix test for hookContext

* chore: fix lint error

* fix: check for hookContext before calling it

* test(transaction): fix hookContext test

* chore: remove whitespace

* test(hookContext): test cloning of context object

* refactor: hookContext -> queryContext

* minor: use more descriptive variable name

i.e. refactor: `context` => `queryContext`

* fix: remove unnecessary checks for query builder

* fix(Raw): pass query builder to formatter

* fix(SchemaCompiler): pass schema builder to formatter

* refactor: add addQueryContext helper

* feat: add queryContext to TableBuilder and ColumnBuilder

* fix(TableCompiler): pass table builder to formatter

* fix(ColumnCompiler): pass column builder to formatter

* fix(pushQuery): fix passing builder to formatter

* test(Schema|Table|ColumnCompiler): test passing queryContext

* fix(SchemaCompiler): pass queryContext to TableCompiler

* fix(TableCompiler): pass queryContext to ColumnCompiler

* test: add queryContext tests for all schema dialects

* test(TableCompiler): test overwriting queryContext from SchemaCompiler

* test(Raw): test passing queryContext to wrapIdentifier

* tests: run all the tests
2018-02-02 00:41:01 +02:00
Igor Savin
09eb12638c Update dependencies and fix ESLint warnings accordingly (#2433)
* Update dependencies. Tweak ESLint rules to work more like they used to before

* Fix indentation

* Remove unnecessary escapes.

* Remove unused 'usingClause' parameter.

* Address CI failures.

* Revert "Remove unused 'usingClause' parameter."

This reverts commit aaa4d71e914faa1c4c1313c26bbdd26067b0b448.

* eslint: add ignore with todo

* dependencies: update
2018-02-01 23:46:12 +02:00
tmeinders
c1997e9502 Fixing issue with add columns on tables failing if using both after and collate (#2432)
* Fixing issue with add columns on tables failing if using both after and collate

* Adding tests for collate modifier alongside first and after modifiers
2018-01-24 02:06:25 +02:00
Sami Koskimäki
45f5ffbad0 Use wrapIdentifier in columnInfo. fixes #2402 (#2405)
* Make postgres client wrapIdentifierImpl independent of `this` context

 * Also fixes a bug where only single digit indices were accepted.

* add customWrapIdentifier helper for client

 * customWrapIdentifier is one more level of abstraction for the wrapIdentifier "pipeline"
   that allows the custom wrapIdentifier to be called without calling the `wrapIdentifierImpl`

* bufix: use custom wrapIdentifier in columnInfo. fixes #2402
2018-01-03 00:05:48 +02:00
Ivo Meißner
fbf371f4e9 Added decimal variable precision / scale support (#2353)
* Added postgres decimal variable precision / scale support

* Decimal column no precision support all dialects + tests
2017-11-30 23:05:39 +02:00
Jürg Lehni
b5ba51a01e Fix truncate() on sqlite3 dialect (#2348)
Relates to #2312: ids were not correctly reset anymore
2017-11-24 09:00:20 +02:00
Mikael Lepistö
c0ac1077b6
More pool tests and test on borrow default (#2341)
* Test pool eviction when DB closes connection

* Added couple of tests for how pool works and added testOnBorrow to defaults
2017-11-19 18:43:28 +02:00
wubzz
95e5cf8e1c
Support multiple searchPaths while preserving case-sensitive feature … (#2340)
* Support multiple searchPaths while preserving case-sensitive feature (by using Array syntax). Fixes #2335

* ESLint

* Added changelog text
2017-11-18 17:09:05 +01:00