162 Commits

Author SHA1 Message Date
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
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
rfink
8f7d2e2977 Adding NOT ILIKE for postgres (#2195) 2017-08-24 11:09:57 +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
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
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
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
Alec Hirsch
9404dba928 added clearSelect and clearWhere to query builder (#1912) 2017-02-20 20:12:14 +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
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
Ruben Slabbert
0ae4f3ef95 Mssql update query generates invalid syntax (#1777)
* Updated mssql update compiler with correct syntax

* Updated failing mssql test

* Updated failing tests to add from

* Third times the charm tests
2016-12-06 20:04:30 +11:00
skarbovskiy
9848145f46 allow to use first method as aliased select (#1784)
* allow to use first method as aliased select

* added test case for allow `first as` syntax
2016-11-18 13:43:39 +02:00
Tim Griesser
5890e4d4ea Fix #1733, #920, incorrect postgres array bindings 2016-10-12 00:43:30 -04:00
Tim Griesser
a24e4df638 More test suite fixes 2016-10-09 15:21:04 -04:00
Tim Griesser
82685b57f0 Fix test in 0.12 2016-10-09 15:09:54 -04:00
Tim Griesser
fa30dfb858 Fix #1710 2016-10-09 14:33:51 -04:00
Alexandre Tiertant
67b62d3213 Add having() and on() missing methods and corresponding tests/doc (#1674) 2016-09-19 19:20:12 +03:00
Alexandre Tiertant
69235aed73 add With Clause (#1599)
* Add "with" clause

* Add arguments check to with() and modify some tests

* fix test
2016-09-13 13:14:04 +03:00
Tim Griesser
ee217ce2a1 Fix PG string escaping behavior (#1661)
* Modify test suite to test #1602
We shouldn’t be testing the “default” client class. Replace any
usages with postgresql

* Simplify knex.raw, deprecate global Knex.raw usage

* Remove unused bluebird shim

* Remove old / unused test comments

* Don't capture Pool2 error event

* Fix pg string escaping & parameterization #1602, #1548
2016-09-12 18:01:47 -04:00
Trevor Smith
b1a95b181e Allow named bindings to be escaped. (#1576)
* Allow named bindings to be escaped.

* Use a literal for the named parameter binding regex.
2016-07-19 20:42:49 +03:00
Dmitry Vdovin
289f17e21b Fix incorrect escaping of backslashes in SqlString.escape (#1545) 2016-07-02 00:45:50 +03:00
Alexandre Tiertant
53d089bffb add node-oracledb support (#990)
* add node-oracledb support

* move file in src directory

* remove unused var

* correct pool release
correct date error

* correct bugs

* add some test

* correct a test error

* correct time zone error in schema tests

* correct time zone error in schema tests

* use inheritance to remove duplicated code

* use inherit in formatter to remove dupplicated code

* remove unused code

* remove unused require

* add blob insert support

* add queryCompiler to dialect prototype

* export queryCompiler

* fix bugs

* Correct tests

* handle returning

* clean code

* clean code

* Fix returning

* Multiple insert with blob

* Add SELECT BLOB support

* Finalise update

* Fix test error

* Fix insert error without returning

* Add transaction and code cleaning

* build

* Fix pool ping error

* Add missing rejecter

* build

* Fix error in delete

* Fix transaction rollback error throwing

* Fix typo in commit

* Fix rollback rejecter

* Remove BLOB tests

* remove lib file

* fixed oracledb linter errors

* Add .completed to transaction acquireConnection()
2016-06-20 18:03:52 +03:00
wubzz
1fe657ab72 Fix test for undefined bindings and add documentation 2016-05-30 21:17:45 +02:00
wubzz
636a446b6d Made the compiler's where function be the source of the validation, but the toSQL function is still the 'thrower'. 2016-05-30 20:09:16 +02:00
wubzz
cba2cdc364 Check for undefined bindings in SELECT queries and RAW queries during compile and throw an error. 2016-05-28 19:45:00 +02:00
wubzz
f097e9147b Make sure 'raw' respects the "not" flag in the query builder. Fixes #1402 2016-05-14 22:36:13 +02:00
Rhys van der Waerden
a06b44a29c Merge pull request #1397 from atiertant/join-nest-statements
Allow joins to nest conditional statements
2016-05-14 11:19:51 +10:00
Mikael Lepistö
9114bdd8b3 Changed implementation of replacing undefined with DEFAULT already in query compiler for every dialect. 2016-05-12 10:24:42 +03:00
Mikael Lepistö
9fab58c2b2 Evaluated multi insert default for undefined already in query compiler 2016-05-12 10:24:42 +03:00
Alexandre Tiertant
f3c78f6c85 add test 2016-05-12 09:09:42 +02:00
wubzz
34d9a7650e Merge pull request #1269 from wubzz/bugfix/fix_valuesForUndefined_actual_query
Fix valuesForUndefined actual query being executed. Fixes #1268
2016-03-27 17:28:41 +02:00
Ryan Fink
dc92ff2b71 Merged upstream 2016-03-24 09:22:07 -04:00
wubzz
02281ef91b Fix valuesForUndefined actual query being executed. Fixes #1268 2016-03-15 21:47:58 +01:00
wubzz
b614a2f81c Update regex for named bindings 2016-03-11 20:41:19 +01:00
Rod Calumpong
ab003ac7c9 Allow returning to be used with oracle update 2016-03-07 16:35:04 -08:00
wubzz
942877c0fe OrWhere({..}) Treat as 'AND', not 'OR'. Fixes #1118 2016-02-18 06:28:14 +01:00
Rhys van der Waerden
5ebbeb07b4 Merge branch 'bugfix/make_raw_backwards_compatible' of https://github.com/wubzz/knex into wubzz-bugfix/make_raw_backwards_compatible 2016-02-06 14:08:30 +11:00