@@ -209,6 +209,63 @@ describe('count empty primary key array', () => {
209209 }
210210} ) ;
211211
212+ describe ( 'distinct' , ( ) => {
213+ test ( 'pg' , async ( ) => await verify ( 'pg' ) ) ;
214+ test ( 'pglite' , async ( ) => await verify ( 'pglite' ) ) ;
215+ test ( 'oracle' , async ( ) => await verify ( 'oracle' ) ) ;
216+ test ( 'mssql' , async ( ) => await verify ( 'mssql' ) ) ;
217+ if ( major === 18 )
218+ test ( 'mssqlNative' , async ( ) => await verify ( 'mssqlNative' ) ) ;
219+ test ( 'mysql' , async ( ) => await verify ( 'mysql' ) ) ;
220+ test ( 'sqlite' , async ( ) => await verify ( 'sqlite' ) ) ;
221+ test ( 'sap' , async ( ) => await verify ( 'sap' ) ) ;
222+ test ( 'http' , async ( ) => await verify ( 'http' ) ) ;
223+
224+ async function verify ( dbName ) {
225+ const { db } = getDb ( dbName ) ;
226+
227+ const rows = await db . orderLine . distinct ( {
228+ orderId : x => x . orderId ,
229+ } ) ;
230+
231+ rows . sort ( ( a , b ) => a . orderId - b . orderId ) ;
232+
233+ expect ( rows ) . toEqual ( [
234+ { orderId : 1 } ,
235+ { orderId : 2 }
236+ ] ) ;
237+ }
238+ } ) ;
239+
240+ describe ( 'distinct fallback group by' , ( ) => {
241+ test ( 'pg' , async ( ) => await verify ( 'pg' ) ) ;
242+ test ( 'pglite' , async ( ) => await verify ( 'pglite' ) ) ;
243+ test ( 'oracle' , async ( ) => await verify ( 'oracle' ) ) ;
244+ test ( 'mssql' , async ( ) => await verify ( 'mssql' ) ) ;
245+ if ( major === 18 )
246+ test ( 'mssqlNative' , async ( ) => await verify ( 'mssqlNative' ) ) ;
247+ test ( 'mysql' , async ( ) => await verify ( 'mysql' ) ) ;
248+ test ( 'sqlite' , async ( ) => await verify ( 'sqlite' ) ) ;
249+ test ( 'sap' , async ( ) => await verify ( 'sap' ) ) ;
250+ test ( 'http' , async ( ) => await verify ( 'http' ) ) ;
251+
252+ async function verify ( dbName ) {
253+ const { db } = getDb ( dbName ) ;
254+
255+ const rows = await db . orderLine . distinct ( {
256+ orderId : x => x . orderId ,
257+ count : x => x . count ( x => x . id ) ,
258+ } ) ;
259+
260+ rows . sort ( ( a , b ) => a . orderId - b . orderId ) ;
261+
262+ expect ( rows ) . toEqual ( [
263+ { orderId : 1 , count : 2 } ,
264+ { orderId : 2 , count : 1 }
265+ ] ) ;
266+ }
267+ } ) ;
268+
212269const pathSegments = __filename . split ( '/' ) ;
213270const lastSegment = pathSegments [ pathSegments . length - 1 ] ;
214271const fileNameWithoutExtension = lastSegment . split ( '.' ) [ 0 ] ;
0 commit comments