994 Commits

Author SHA1 Message Date
Igor Savin
776a115c73 Add json type support for SQLite (#2814)
* Add json type support for SQLite 3.9+ (which is node-sqlite 4.0.0+, I think)

* Remove unneeded import
2018-09-26 09:15:31 +03:00
Jake Ginnivan
bf1e384ed6 Introduced abstraction for getting migrations (#2775)
* Introduced abstraction for getting migrations

This would allow a webpack migration source which is compatible with bundling.

* Fixed migration validation with custom migration source

* Fixed issues after rebasing on muti directory PR

* Renamed parameter and fixed error message

* Addressed some PR comments

* Finished comment

* Moved filename extension filtering into fs-migrator

* Added test showing in memory custom migration source

* Cleaned up how to get config

* Fixed failing test

* Hopefully fix tests

* Fix Node.js 10 support in tests
2018-09-12 14:58:37 +03:00
Simon Lidén
1616b2af0d Use columnize instead of wrap in using(). (#2713)
* Use columnize instead of wrap in using().

This is an attempt to fix #2136. Also added an integration test, couldn't find any existing.

* Exclude MSSQL from test as it does not support .using

* Change test to not use subquery

* Change test
2018-08-29 20:43:45 +03:00
Igor Savin
89d2b3a5e1 #2758: Implement fail-fast logic for dialect resolution (#2776)
* Implement fail-fast logic for dialect resolution, clean-up code around.

* Remove method that was deprecated long time ago

* Address additional comments

* Try addressing comments

* Set client explicitly

* Fix compatibility with older Node versions
2018-08-29 18:13:16 +03:00
Igor Savin
91f23bc02f Feature/2690: Multiple migration directories (#2735)
* Implement support for multiple migration directories

* Add tests for new functionality

* Fix tape tests

* Pass migration directory upwards

* Fix multiple directory support

* Fix bugs

* Rollback correctly

* Fix remaining tests

* Address comments
2018-08-24 12:39:20 +03:00
Caíque de Castro Soares da Silva
337455f63a Allow timestamp with timezone on mssql databases (#2724)
* Allow timestamp with timezone on mssql databases

* Change timestamp parameter to use object instead of boolean
2018-08-23 13:10:19 +03:00
Will Morgan
fac313f27f Use Datetime2 for MSSQL datetime + timestamp types (#2757)
* Use Datetime2 for MSSQL datetime + timestamp types

Datetime2 is now the recommended column type for new date work: https://docs.microsoft.com/en-us/sql/t-sql/data-types/datetime-transact-sql?view=sql-server-2017

* Add tests for MSSQL datetime2 changes
2018-08-13 15:33:37 -05:00
Simon Lidén
2183a27826 Fix join using builder withSchema. (#2744) 2018-08-04 18:50:50 +03:00
Simon Lidén
30bab697ba Compile with before update so that bindings are put in correct order (#2733) 2018-08-04 18:33:10 +03:00
Scott Trinh
bf1a2dcb93 Add tests for multiple union arguments with callbacks and builders (#2749)
* Add tests for multiple union arguments

* Add some callback and raw tests to union unit tests
2018-08-03 21:11:38 +02:00
Tim Griesser
4fd16da45a
Fix #2715 (#2721)
* Fix #2715, explicitly set precision in datetime & timestamp
* Allow for precision in knex.fn.now, mysql time
* Add test for datetime with precision
2018-07-19 10:46:23 -04:00
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