222 Commits

Author SHA1 Message Date
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
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