Skip to content

Commit

Permalink
Merge pull request #67 from ZaidMaslouhi/fixes
Browse files Browse the repository at this point in the history
Update Documentation for Join Condition Query Strings
  • Loading branch information
zaro authored Dec 6, 2024
2 parents 6992031 + b05157c commit 98d6532
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ jobs:
test:
# The type of runner that the job will run on
runs-on: ubuntu-latest
env:
COMPOSE_FILE: ./docker-compose.yml
container: node:20
# env:
# COMPOSE_FILE: ./docker-compose.yml

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
- nestjsx_crud

mysql:
platform: linux/x86_64
image: mysql:5.7
ports:
- 3316:3306
Expand All @@ -28,8 +29,8 @@ services:
ulimits:
nproc: 65535
nofile:
soft: 20000
hard: 40000
soft: 20000
hard: 40000

redis:
image: redis:alpine
Expand Down
20 changes: 10 additions & 10 deletions docs/requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ _Syntax:_

> ?filter=**field**||**\$condition**||**value**
> ?join=**relation**&filter=**relation**.**field**||**\$condition**||**value**
> ?join[]=**relation**&filter=**relation**.**field**||**\$condition**||**value**
**_Notice:_** Using nested filter shall join relation first.

Expand Down Expand Up @@ -200,35 +200,35 @@ Receive joined relational objects in GET result (with all or selected fields). Y

_Syntax:_

> ?join=**relation**
> ?join[]=**relation**
> ?join=**relation**||**field1**,**field2**,...
> ?join[]=**relation**||**field1**,**field2**,...
> ?join=**relation1**||**field11**,**field12**,...&join=**relation1**.**nested**||**field21**,**field22**,...&join=...
> ?join[]=**relation1**||**field11**,**field12**,...&join[]=**relation1**.**nested**||**field21**,**field22**,...&join[]=...
_Examples:_

> ?join=**profile**
> ?join[]=**profile**
> ?join=**profile**||**firstName**,**email**
> ?join[]=**profile**||**firstName**,**email**
> ?join=**profile**||**firstName**,**email**&join=**notifications**||**content**&join=**tasks**
> ?join[]=**profile**||**firstName**,**email**&join[]=**notifications**||**content**&join[]=**tasks**
> ?join=**relation1**&join=**relation1**.**nested**&join=**relation1**.**nested**.**deepnested**
> ?join[]=**relation1**&join[]=**relation1**.**nested**&join[]=**relation1**.**nested**.**deepnested**
**_Notice:_** primary field/column always persists in relational objects. To use nested relations, the parent level **MUST** be set before the child level like example above.

### New Feature: Join Condition (on clause)

The join parameter now supports specifying a WHERE condition within the ON clause of the join using the on property. This allows for more granular control over the joined data.

> ?join=**relation**||**field1**,**field2**,...||on[0]=**field**||**\$condition**||**value**,on[1]=**field**||**\$condition**...&join=...
> ?join[]=**relation**||**field1**,**field2**,...||on[0]=**field**||**\$condition**||**value**,on[1]=**field**||**\$condition**...&join[]=...
_Examples:_

Suppose you want to retrieve `Posts` along with their associated `Author` data, but you only want to include `Authors` where the `isActive` field is `true` and the `profilePicture` field is `null` (meaning the author doesn't have a profile picture set). You can achieve this with the following query string:

> ?join=**author**||**fullName**,**email**||on[0]=**author.isActive**||**\$eq**||**true**&on[1]=**author.profilePicture**||**\$isnull**
> ?join[]=**author**||**fullName**,**email**||on[0]=**author.isActive**||**\$eq**||**true**&on[1]=**author.profilePicture**||**\$isnull**
This query will join the `Post` entity with its related `Author` entity, but it will only include `Author` objects where:

Expand Down

0 comments on commit 98d6532

Please sign in to comment.