994 Commits

Author SHA1 Message Date
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
Mikael Lepistö
e405d669a6
Fixed passing connection errors directly to the query (#2336)
* Fixed passing connection errors directly to the query

* Added missing use strict and fixed select to be oracle compatible.

* Fixed dialect name which is mixed in different configs

* Oracledb didnt have database config attribute
2017-11-17 21:03:43 +02:00
Jonathan Stewmon
7c1a0d4fc0 mysql stream should support query options (#2301) 2017-11-05 18:47:21 +02:00
Richard Ižip
74f2a031f3 Throw error on non-string table comment (#2126)
* Throw error on non-string table comment

* add unit tests for all dialects
* removed non-valid comments retyping to ''

* Change dockerode version

* reverted dockerode version locking
2017-11-01 00:22:07 +02:00
Mikael Lepistö
7d18837404
Allow update queries in with statements. Fixes #2263. (#2298) 2017-10-31 21:33:28 +02:00
Juuso Tapaninen
fddfd3b3d8 Escape table name in SQLite columnInfo call (#2281)
Fixes #2184. Not escaping the table name could lead to issues
with some table names. Table name group, for example, would
result in an error.
2017-10-23 09:13:09 +03:00
Ivan Filho
11536f92ff Implemented select syntax: select({ alias: 'column' }) (#2227)
* added object syntax for aliases

* added mixed tests for alias pair feature

* fixed double aliasing for subqueries

* fixed last untested commit

* Added support for passing query builder inside object syntax and using the syntax in raw identifiers
2017-10-17 01:43:20 +03:00
Mike
b092a271fa Allow raw expressions in query builder aggregate methods (#2257)
The aggregate methods include `count`, `min`, `max`, `sum`, `avg`,
`countDistinct`, `sumDistinct`, and `avgDistinct`, all of which
can now receive raw expressions, e.g.

```js
knex('users').count(knex.raw("data->'active'"));
```

There seems to be some demand for this, and I think it's cleaner than the alternative of

```js
knex('users').select(knex.raw("count(data->'active')"));
```
2017-10-14 18:19:06 +03:00
Mikael Lepistö
9658c78d4f Post processing hook for query result (#2261) 2017-10-12 18:16:15 +03:00
Mark Wubben
0ccd591bcb Fix connection error propagation when streaming (#2199)
* Fix connection error propagation when streaming

If stream() is used without a handler, make sure to emit connection
errors on the stream itself.

* Test stream error emission

* Improve test
2017-10-03 19:39:10 +03:00
Rich Dillon
7032dffe70 Fix comments not being applied to increments columns (#2243)
* Removed check increments check on the modifiers. Implemented a default lookup map on the generic columncompiler

* Ignore VS Code User Workspace Settings

* Added test case to assert comments are added to increments columns

* Shortened line length and added explicit db tests for postgres and mysql dialects

* Added check for modifiers on incrementing types and only allow comment modifiers
2017-09-28 08:54:20 +03:00
Mikael Lepistö
15639d03db Build native sql for a dialect without to string (#2237)
* Exposed also positionBinding method to client base class and refactored calls to em

* Added toSQL().toNative() getter which returns dialect specfic sql and bindings.

* Refactored toSQL method implementation
2017-09-27 13:12:40 +03:00
Mikael Lepistö
491cc788c2 Updated oprator list and allow operator transformation for e.g. escaping ? (#2239) 2017-09-23 14:34:59 +03:00
Mikael Lepistö
b5d93f10b1 Configuration option to allow override/hook to identifier wrapping code (#2217) 2017-09-08 14:58:59 +03:00
Jonathan Stewmon
9122cbf6df upgrade generic-pool to 3.1.7 (#2208)
* Upgrade generic-pool to v3.1.7 (Attempt)

* Remove callback from pool create function

* Fix ESLint

* Send whole poolConfig to generic-pool (for idleTimeoutMillis etc)

* fix compatibility issues with generic-pool v3
- restore Client.poolDefaults to allow dialect overrides
- connection validators should always resolve with a boolean
- rely on generic pool acquire timeouts to avoid unhandled rejections
- simplify promise usage, avoiding Promise constructor anti-pattern
- enable testOnBorrow in docker tests to evict broken connections
- enable docker tests on Darwin
- enable docker tests for mysql2 dialect

* validate timeout settings and to 60s

* simplify Client.destroy promise handling

* return destroyRawConnection promise from dialects
2017-09-06 22:51:29 +03:00
rfink
8f7d2e2977 Adding NOT ILIKE for postgres (#2195) 2017-08-24 11:09:57 +03:00
Kurre Ståhlberg
03f0fb426c Remove sorting of statements from UPDATE (#2169) (#2171) 2017-07-26 11:36:50 +03:00
doomsower
1c61ad898f Allows to filter seeds and migrations by extensions (#2168)
* Added `loadExtensions` parameter to filter which migrations and seeds will be executed

* `loadExtensions` now includes all supported extensions by default
Also added unit tests for modified code
2017-07-24 14:19:17 +03:00
Mikael Lepistö
c7dfcb6292 Fixing docker CI tests (#2164)
* Fixing docker CI tests

* Removed support for node 0.12 and added node 8 to CI

* Trying to fix babel issue happening on node 8

* Could not reproduce the problem on local install... disabling node 8 travis tests for now.
2017-07-23 16:33:25 +03:00
Richard Ižip
298a5854ec Add unit test for right/rightOuterJoin combination (#2117)
* Do not include test for sqlite3 because it
  currently does not support right join
2017-06-26 20:16:37 +03:00
Richard Ižip
d10b0d00b2 Add fullOuterJoin unit test (#2118)
* No fullOuterJoin for MySQL and sqlite3
  because they do not support it
2017-06-26 20:01:33 +03:00
Richard Ižip
16a4eb1455 Fix adding more columns in Oracle (#2115)
* Fix incorrent unit tests to reflect
  current changes
2017-06-10 21:01:57 +03:00
Richard Ižip
e63fe22555 Add unit tests for table comment (#2098)
* Tests for setting comment on table for postgresql, mysql and oracle

* No tests for sqlite as it does not seem to support comments

* No tests for mssql as it can not be tested simply using sql comparison
2017-06-10 20:47:51 +03:00
irsl
5fc456cb69 integration test for sqlite3, referencing non-existent column in the query (#2104)
* integration test for sqlite3, referencing non-existent column in the query

* making node 0.12 happy
2017-06-10 01:20:59 +03:00
Dave Grochowski
c18374e269 Use the schema when dropping indices in Postgres. (#2105) 2017-06-10 01:07:57 +03:00
Richard Ižip
e88490342e Add unit test for renaming column in postgresql (#2099) 2017-06-10 00:53:25 +03:00
Richard Ižip
3d9316686a Add unit test for cross-join (#2102)
* Test composition of two cross joins

* Test cross-join with 'on' statement
  (same as inner join) only for sqlite3 and mysql
  because not supported elsewhere
2017-06-10 00:29:56 +03:00
Ronny Badilla
198da1b273 Change the way that MySQL verifies if a table exists (#2097) 2017-06-09 23:19:37 +03:00
smulesoft
31ba04a788 fixes #1833 on postgres (#2017)
* fixes #1833 on postgres

* adds @elhigu requested changes

* adds test when database is down

* adds script for docker support

* removes old comment

* fixes syntax

* fixes more syntax errors

* fixes final syntax errors

* Docker testing enabled only on linux for now
2017-06-01 22:41:35 +03:00
irsl
a47a077330 Field identifiers were not quoted properly in Sqlite3 dialect (#2087)
* field wrapping changed from quotes to backticks in sqlite3 dialect; unit tests adjusted accordingly

* addColumn was accidently removed
2017-05-28 23:48:18 +03:00
dirkmc
67951700ca Fix mssql binding ordering for queries that combine a limit with select raw or update (#2066)
* Fix binding ordering for queries that combine a limit with a select raw or update

* Use old school quotes so tests pass
2017-05-16 13:51:24 +03:00
GONZO
68af752bbe fixed table alter attributes order. (first, after) (#2062)
* fixed table alter attribute order. (first, after)

* add test cases, alter table position with comment.

* add real database test cases.

* after, first tests only mysql or mariadb.
2017-05-15 13:16:15 +03:00
Carlos Ramos
18581f9632 Add support for enum columns to SQlite3 dialect (#2055) 2017-05-10 20:04:13 +03:00
Alexandre Tiertant
dd3289be94 Add fetchAsString optional parameter to oracledb dialect (#1998)
* Add optional parameter fetchAsString to oracledb

* Add some checks to oracle fetchAsString

* use const instead of let

* add fetchAsString test

* change const to var in tests

* move oracle driver specific test to bottom

* fix fetchAsSting multiple instance

* Fix tests

* replace const to var in test

* Rework Oracle fetchAsString tests

* remove const

* remove done and timeout
2017-04-28 13:47:24 +03:00
Tjerk Santegoeds
5c0b193fec fix: escapeObject parameter order for Postgres dialect. (#2003)
* fix: escapeObject parameter order for Postgres dialect.

* test: escapeObject for Postgres dialect.
2017-04-12 13:57:27 +03:00
itaysabato
a5f4c39529 Migration transaction (#1962)
* Use transaction for entire migration batch + locking if all migrations are transactional.

* Fix tests.
Use knex instead of query builder.
Do no use single transaction if `disableTransactions` is true.

* Added tests for parallel migrations.
Subtract already done migrations after getting the lock, when there is a wrapping transaction.

* Fix indentation.

* Fix linting errors (which are locally warnings, for some reason).

* Remove `const` keyword.
Remove obsolete `it` clauses.

* No maria. PG first.

* Test only pg and oracle.

* Remove error swallowing.

* Test parallel migration only in postgres (select for update works differently in other databases).

* Add transaction to missed places.

* Remove ignored table name argument.

* Enabled parallel migrations test for `mssql` dialect (still not part of CI test).
Fixed indentation.
2017-03-27 17:39:08 +03:00
Mikael Lepistö
137e1fe987 Allow passing version of connected db in configuration file (#1993)
* # This is a combination of 3 commits.
# The first commit's message is:
Allow passing config.version variable to knex instead of parsing the DB version from string returned form DB server.

This makes it possible to connect custom databases which are compatible with an official database of certain version.

# The 2nd commit message will be skipped:

#	Update checkVersion
#
#	To use `const` instead of `let` to fix lint error

# The 3rd commit message will be skipped:

#	Revert "Update checkVersion"
#
#	This reverts commit 248907decb94f0df2f2b3b9fe114738fb48394fc.

* Allow passing config.version variable to knex instead of parsing the DB version from string returned form DB server.

This makes it possible to connect custom databases which are compatible with an official database of certain version.
2017-03-27 00:21:15 +03:00
Mikael Lepistö
9682446e08 Fixed transaction promise mutation issue (#1991)
* Fixed transaction promise to not be overridden

* Disabled failing test case until #1970 feature if fixed.
2017-03-26 19:43:36 +03:00
wubzz
138e13b8b1 Bugfixes on batchInsert and transactions for mysql/maria (#1992) 2017-03-26 18:43:17 +03:00
wubzz
876f615f61 Increase test timeout 2017-03-24 16:14:25 +01:00