-
-
Notifications
You must be signed in to change notification settings - Fork 568
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: json field grouping and multi-value field SUM in base query inte…
…rface (#1027) * fix: json field grouping and multi-value field SUM in base query interface * fix: base query joinSelect support sqlite
- Loading branch information
Showing
9 changed files
with
113 additions
and
8 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
apps/nestjs-backend/src/db-provider/base-query/abstract.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { Knex } from 'knex'; | ||
|
||
export abstract class BaseQueryAbstract { | ||
constructor(protected readonly knex: Knex) {} | ||
|
||
abstract jsonSelect( | ||
queryBuilder: Knex.QueryBuilder, | ||
dbFieldName: string, | ||
alias: string | ||
): Knex.QueryBuilder; | ||
} |
16 changes: 16 additions & 0 deletions
16
apps/nestjs-backend/src/db-provider/base-query/base-query.postgres.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { Knex } from 'knex'; | ||
import { BaseQueryAbstract } from './abstract'; | ||
|
||
export class BaseQueryPostgres extends BaseQueryAbstract { | ||
constructor(protected readonly knex: Knex) { | ||
super(knex); | ||
} | ||
|
||
jsonSelect( | ||
queryBuilder: Knex.QueryBuilder, | ||
dbFieldName: string, | ||
alias: string | ||
): Knex.QueryBuilder { | ||
return queryBuilder.select(this.knex.raw(`MAX(??::text) AS ??`, [dbFieldName, alias])); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
apps/nestjs-backend/src/db-provider/base-query/base-query.sqlite.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { Knex } from 'knex'; | ||
import { BaseQueryAbstract } from './abstract'; | ||
|
||
export class BaseQuerySqlite extends BaseQueryAbstract { | ||
constructor(protected readonly knex: Knex) { | ||
super(knex); | ||
} | ||
|
||
jsonSelect( | ||
queryBuilder: Knex.QueryBuilder, | ||
dbFieldName: string, | ||
alias: string | ||
): Knex.QueryBuilder { | ||
return queryBuilder.select(this.knex.raw(`MAX(??) AS ??`, [dbFieldName, alias])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters