From 573ee725a23da251d3bd9b44017522370fa28980 Mon Sep 17 00:00:00 2001 From: Markus Wendorf Date: Wed, 14 Feb 2024 13:05:26 +0100 Subject: [PATCH] add additional information to complex join example (#883) --- package-lock.json | 7 +++++++ package.json | 1 + site/docs/examples/JOIN/0030-complex-join.js | 1 + site/docs/examples/JOIN/0030-complex-join.mdx | 6 ++++-- src/query-builder/select-query-builder.ts | 7 +++++-- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index d381fcdd9..6992107c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "chai-as-promised": "^7.1.1", "chai-subset": "^1.6.0", "esbuild": "^0.19.11", + "lodash": "^4.17.21", "mocha": "^10.2.0", "mysql2": "^3.6.5", "pg": "^8.11.3", @@ -2641,6 +2642,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "dev": true + }, "node_modules/lodash.get": { "version": "4.4.2", "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", diff --git a/package.json b/package.json index 22d3d7142..69aef4707 100644 --- a/package.json +++ b/package.json @@ -84,6 +84,7 @@ "chai-as-promised": "^7.1.1", "chai-subset": "^1.6.0", "esbuild": "^0.19.11", + "lodash": "^4.17.21", "mocha": "^10.2.0", "mysql2": "^3.6.5", "pg": "^8.11.3", diff --git a/site/docs/examples/JOIN/0030-complex-join.js b/site/docs/examples/JOIN/0030-complex-join.js index 896320bb1..347b4dc56 100644 --- a/site/docs/examples/JOIN/0030-complex-join.js +++ b/site/docs/examples/JOIN/0030-complex-join.js @@ -4,6 +4,7 @@ export const complexJoin = `await db.selectFrom('person') (join) => join .onRef('pet.owner_id', '=', 'person.id') .on('pet.name', '=', 'Doggo') + .on((eb) => eb.or([eb("person.age", ">", 18), eb("person.age", "<", 100)])) ) .selectAll() .execute()` \ No newline at end of file diff --git a/site/docs/examples/JOIN/0030-complex-join.mdx b/site/docs/examples/JOIN/0030-complex-join.mdx index 8943a4e69..564277e82 100644 --- a/site/docs/examples/JOIN/0030-complex-join.mdx +++ b/site/docs/examples/JOIN/0030-complex-join.mdx @@ -8,8 +8,10 @@ You can provide a function as the second argument to get a join builder for creating more complex joins. The join builder has a bunch of `on*` methods for building the `on` clause of the join. There's basically an equivalent for every `where` method -(`on`, `onRef` etc.). You can do all the same things with the -`on` method that you can with the corresponding `where` method. +(`on`, `onRef` etc.). + +You can do all the same things with the +`on` method that you can with the corresponding `where` method (like [OR expressions for example](https://kysely.dev/docs/examples/WHERE/or-where)). See the `where` method documentation for more examples. import { diff --git a/src/query-builder/select-query-builder.ts b/src/query-builder/select-query-builder.ts index 2d1d072db..b44ca176c 100644 --- a/src/query-builder/select-query-builder.ts +++ b/src/query-builder/select-query-builder.ts @@ -580,8 +580,10 @@ export interface SelectQueryBuilder * builder for creating more complex joins. The join builder has a * bunch of `on*` methods for building the `on` clause of the join. * There's basically an equivalent for every `where` method - * (`on`, `onRef` etc.). You can do all the same things with the - * `on` method that you can with the corresponding `where` method. + * (`on`, `onRef` etc.). + * + * You can do all the same things with the + * `on` method that you can with the corresponding `where` method (like [OR expressions for example](https://kysely.dev/docs/examples/WHERE/or-where)). * See the `where` method documentation for more examples. * * ```ts @@ -591,6 +593,7 @@ export interface SelectQueryBuilder * (join) => join * .onRef('pet.owner_id', '=', 'person.id') * .on('pet.name', '=', 'Doggo') + * .on((eb) => eb.or([eb("person.age", ">", 18), eb("person.age", "<", 100)])) * ) * .selectAll() * .execute()