201 Commits

Author SHA1 Message Date
EthanHur
c53227564d add validation in .offset() (#2908) 2019-10-15 13:24:49 +02:00
Igor Savin
988fb24389
Fix MSSQL escaping (#3382) 2019-10-06 20:21:32 +02:00
Kristjan
4ade98980e feat: add undefined columns to undefined binding(s) error (#3425) 2019-09-04 22:59:04 +02:00
Ricardo Graça
9aa7085b05 Rename src directory to lib (#3338) 2019-07-10 23:48:43 +02:00
Igor Savin
e971c5198b
Update dependencies, fix new eslint errors (#3339) 2019-07-10 20:47:56 +02:00
Ricardo Maes
bc1ddcad01 Implement "skipLocked()" and "noWait()" (#2961) 2019-07-06 14:05:53 +02:00
Igor Savin
c431ffc35a
Drop support for Node.js 6. Remove babel. (#3227) 2019-06-04 00:37:17 +02:00
Igor Savin
5307dacc66
Implement support for returning started transaction without using transaction() methods callback function (#3099) 2019-05-26 18:03:07 -07:00
Lorefnon
54a7a4a35f Support multi-column whereIn in sqlite through values clause (#3220)
Fixes #3042
2019-05-25 12:53:20 -07:00
Daniel Mills
617d36ea01 add clearHaving function and add test (#3141) 2019-05-12 10:20:26 +02:00
Andrew Schmadel
b15ee3def1 make unionAll()'s call signature match union() (#3055)
* make unionAll()'s call signature match union()

consolidates the logic used by union() and unionAll(), allowing the two to be used interchangeably

* use spread args instead of arguments array

* Fix unionAll spread arguments
2019-03-29 19:55:32 +02:00
EthanHur
0db785949b add test that clearing offset (#2954)
* add test that clearing offset

* fix typo
2019-03-05 16:25:30 +01:00
thekuom
71e097b663 add intersect() (#3023)
* add intersect()

* update intersect integration tests to validate results

* use const instead of var, remove .only in test, remove commented out type
2019-03-03 20:57:40 +01:00
EthanHur
dfe01298d2 mysql warn .returning() does not have any effect. (#3039)
* mysql warn `.returning()` does not have any effect.

* add test if warning is emitted or not
2019-03-03 14:53:06 +02:00
EthanHur
723346f7c5 fix client typo in test script (#2912) 2018-11-16 14:36:33 +01:00
EthanHur
4db047df02 support multiple columns in .orderBy() (#2881)
* support multiple columns in `.orderBy()`

* add unit tests of order by

* orderByArray function to private

* use isString in string check
2018-11-06 22:30:06 +01:00
Casey Foster
c0838053bd Add withRecursive() (#2889)
* Add withRecursive()
2018-11-04 20:30:04 -05:00
Igor Savin
96a8e3a4d8 Add support for named unique, primary and foreign keys to SQLite3 (#2840)
* Add support for named unique, primary and foreign keys to SQLite3

* Add integration testing for named keys

* Improve tests for primary and unique keys

* Improve tests for foreign keys

* Run prettier

* Fix tests

* Fix additional test
2018-10-11 19:14:26 +03:00
Simon Lidén
66acbe7719 Allow chaining of increment, decrement, and update (#2740)
* Allow chaining of increment, decrement, and update
* Adds clearCounters
2018-10-06 10:10:56 -04:00
sgoll
1c782cf2c8 Allow table names with forUpdate/forShare (tgriesser/knex#2834) (#2835)
* Allow table names with forUpdate/forShare (tgriesser/knex#2834)

* Add integration test for partial table locks

* Simplify code of table name concatenation

* Add changelog entry
2018-10-04 09:39:24 -04:00
Tim Griesser
051bdc7e2a
whereColumn (#2837)
Adds: 
  - whereColumn
  - orWhereColumn
  - andWhereColumn
  - whereNotColumn
  - andWhereNotColumn
  - orWhereNotColumn
2018-10-03 11:26:19 -04:00
Tim Griesser
ca00ddb9c5 Revert "onVal -> onColumn for #2746"
This reverts commit b83fc4db476d596d3fb136f187cd91cb7f1dbcfe.
2018-10-03 09:32:29 -04:00
Tim Griesser
b83fc4db47 onVal -> onColumn for #2746 2018-10-02 22:49:12 -04:00
Simon Lidén
0b417e5371 Feature/join onVal andOnVal orOnVal (#2746)
* Added onVal, andOnVal, orOnVal to JoinClause
2018-10-02 22:44:46 -04: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
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
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
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
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
Michael Storgaard
51ee9bba17 Fixed onIn with empty values array (#2513) 2018-05-29 12:35:37 -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
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
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
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
074ceaeadd
Allow calling lock procedures (such as forUpdate) outside of transaction. Fixes #2403. (#2475) 2018-02-16 14:06:49 +01: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
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
Mikael Lepistö
7d18837404
Allow update queries in with statements. Fixes #2263. (#2298) 2017-10-31 21:33:28 +02: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ö
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