File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change 1
1
import type { ChainedMethods } from '@payloadcms/drizzle/types'
2
2
3
3
import { chainMethods } from '@payloadcms/drizzle'
4
- import { sql } from 'drizzle-orm'
4
+ import { count , sql } from 'drizzle-orm'
5
5
6
6
import type { CountDistinct , SQLiteAdapter } from './types.js'
7
7
@@ -22,8 +22,11 @@ export const countDistinct: CountDistinct = async function countDistinct(
22
22
methods : chainedMethods ,
23
23
query : db
24
24
. select ( {
25
- count : sql < number > `count
26
- (DISTINCT ${ this . tables [ tableName ] . id } )` ,
25
+ count :
26
+ joins . length > 0
27
+ ? sql `count
28
+ (DISTINCT ${ this . tables [ tableName ] . id } )` . mapWith ( Number )
29
+ : count ( ) ,
27
30
} )
28
31
. from ( this . tables [ tableName ] )
29
32
. where ( where ) ,
Original file line number Diff line number Diff line change 1
- import { sql } from 'drizzle-orm'
1
+ import { count , sql } from 'drizzle-orm'
2
2
3
3
import type { ChainedMethods , TransactionPg } from '../types.js'
4
4
import type { BasePostgresAdapter , CountDistinct } from './types.js'
@@ -22,8 +22,11 @@ export const countDistinct: CountDistinct = async function countDistinct(
22
22
methods : chainedMethods ,
23
23
query : ( db as TransactionPg )
24
24
. select ( {
25
- count : sql < string > `count
26
- (DISTINCT ${ this . tables [ tableName ] . id } )` ,
25
+ count :
26
+ joins . length > 0
27
+ ? sql `count
28
+ (DISTINCT ${ this . tables [ tableName ] . id } )` . mapWith ( Number )
29
+ : count ( ) ,
27
30
} )
28
31
. from ( this . tables [ tableName ] )
29
32
. where ( where ) ,
You can’t perform that action at this time.
0 commit comments