833 Commits

Author SHA1 Message Date
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
wubzz
50557f7571 Ensure errors in batchInsert do not end up 'unhandled'. Fixes #1880 (#1984) 2017-03-22 21:44:36 +01:00
wubzz
b722753ea3 Transaction should not reject with undefined. (#1970) 2017-03-14 21:56:32 +01:00
Alec Hirsch
9404dba928 added clearSelect and clearWhere to query builder (#1912) 2017-02-20 20:12:14 +02:00
vellotis
fe4ec15ae0 Support custom foreign key names (continued work of #1311) (#1726)
* Added support for custom foreign key name

* Update unit test for #1311

* Fix TableCompiler::foreign to respect previous behavior + typo

* Add dialect specific unit tests

* Fixed comment

Actually trying to trigger travis to run tests with latest travis configuration... (maybe it just doesn't run tests against merged branch..)
2017-02-17 00:35:43 +02:00
Mikael Lepistö
77e67334a3 Alter column syntax for table, implements changing type, nullability and default (#1914)
* Added support for altering columns

* Add mysql dialect key for alter (modify)

* Added tests for .alter()

* Updated dialects for .alter() on column

* .alter() for mssql and tests

* Added an error for sqlite3 alter column

Sqlite does not support alter column at all

* Implemented schema alter column support for postgresql

* Added unit test for alter column and fixed postgres implementation

* Add test case for adding multiple columns at once (oracle check)

* Try upgrading CI mysql / postgres and distro

* Disabled adding multiple columns test from oracle

* Fixed node 0.12 test compatibility

* Fixed review comments
2017-02-16 20:34:59 +02:00
Mathew Gardner
f198c7d574 Allow casting when using named bindings. (#1890)
* Allow casting when using named bindings.

* Remove template string in test.

* Only replace matches that are member to the bindings object.

* Slight refactor for tests.

* Simplify regex.

* Allow casting on named identifiers.
2017-02-05 20:22:26 +02:00
Tim Huff
0d55cfd286 More promise functions (#1896)
* Added failing tests

added more promise tests

* Added ability to use promise functions

* removed identity from promise handler
2017-02-04 02:54:15 +02:00
Justin Huntington
2fa375f813 Pass rollback errors through to transaction promise in mssql dialect (#1884) (#1885)
Check for rollback failures on mssql and pass them through to the transaction promise-- attaching the underlying cause as an 'originalError' property.  This fixes a hang when mssql server aborts a transaction and the client issues a rollback.
2017-01-30 15:00:03 -06:00
Tomás Pinho
7de07c966a ONLY keyword support for PostgreSQL (#1874)
* adding support for ONLY keyword for PostgreSQL as an optional flag of from() and into() through table(tableName, only)

* passing only parameter from default function was missing

* changing only option to options object with only key

* better style per @wubzz suggestion
2017-01-26 18:22:09 +02:00
Mikael Lepistö
49aa6f7314 Check that oracle DB testing is enabled before running ext auth tests. Fixes #1865 (#1867) 2017-01-16 11:05:35 +02:00
wubzz
a4bfee7751 Ensure that 'client' is provided in knex config object (#1822)
* Ensure that 'client' is provided in knex config object

* sqlite3 columncompiler: Assign 'modifiers' --after-- super() call.

* oracle columncompiler: Assign 'modifiers' --after-- super() call.
2016-12-11 18:23:44 +02:00