58 Commits

Author SHA1 Message Date
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
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
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
Tim Griesser
232fe9f151
Add Prettier (#2697)
* Add prettier
* Run files through prettier
2018-07-09 08:10:34 -04: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
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
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
godfrey
59f6cba178 Set toNative() to be not enumerable (#2388) 2018-01-03 17:56:34 +02:00
Mikael Lepistö
7d18837404
Allow update queries in with statements. Fixes #2263. (#2298) 2017-10-31 21:33:28 +02: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
Kurre Ståhlberg
03f0fb426c Remove sorting of statements from UPDATE (#2169) (#2171) 2017-07-26 11:36:50 +03: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
Owen Evans
825396ada7 use uuid not node-uuid (#1792) 2016-11-22 10:58:21 +02: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
Alexandre Tiertant
67b62d3213 Add having() and on() missing methods and corresponding tests/doc (#1674) 2016-09-19 19:20:12 +03:00
Tim Griesser
1413aa057a Add DEBUG=knex:bindings for #1557 2016-09-16 16:04:11 -04:00
Tim Griesser
3a5250d87d Fix #1619 2016-09-13 09:56:53 -04: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
David Overcash
9fe1a06ae1 Better name. 2016-06-17 09:33:03 -07:00
David Overcash
4ab0a916ba Change field name to something more appropriate. 2016-06-17 09:32:07 -07:00
David Overcash
04ddaeaa4a Add uuid based on already used import. 2016-06-17 09:19:20 -07:00
David Overcash
b3e9f29126 Add UUID to query/compiler.js:toSQL 2016-06-17 08:31:42 -07:00
Rhys van der Waerden
a95e39609f Lint before tests in CI 2016-06-14 19:50:51 +10:00
wubzz
a7ba49ae7c Add hasOwnProperty condition 2016-05-30 21:09:15 +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
Byron Wong
ea5cbec4e7 Kill queries after timeout for MySQL 2016-05-26 12:00:47 -07:00
Rhys van der Waerden
06e3447440 Remove duplicate spaces in assignments.
These were previously horizontally aligned. The esnext conversion disrupted them all.
2016-05-18 19:59:24 +10:00
Rhys van der Waerden
3846b7182c Make codebase conform to ESLint rules
Just a couple of changes.
2016-05-17 01:01:34 +10: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ö
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
Alexandre Tiertant
840a585665 fix using 2016-05-11 16:22:15 +02:00
Alexandre Tiertant
eeace3d557 fix param 2016-05-11 15:51:48 +02:00
Alexandre Tiertant
89d85d28a3 fix #690 2016-05-11 15:26:53 +02:00
Rhys van der Waerden
0ccb4bfa87 Modernize method syntax
`name: function()` -> `name()`
2016-05-08 23:18:28 +10:00
wubzz
b32fadf1e8 Prevent potential regression of argument tz (timezone) 2016-03-15 21:53:23 +01:00
wubzz
f286da2796 Preserve original bindings at all times. Move prepBindings calls to toSQL() instead. Enforce 'bindings' to always be present in .toSQL() resultset. 2016-03-15 21:47:59 +01:00
wubzz
02281ef91b Fix valuesForUndefined actual query being executed. Fixes #1268 2016-03-15 21:47:58 +01:00
wubzz
1d27fb8550 Update lodash from 3.7.0 -> 4.6.0 2016-03-15 18:11:13 +01:00