import { generateTestClient } from '../../../../utils/getTestClient' ; const testIf = ( condition ) => ( condition ? test : test . skip ) ; const udsSupportedByOperatingSystem = process . platform !== 'win32' ; testIf ( udsSupportedByOperatingSystem ) ( 'blog' , async ( ) => { await generateTestClient ( ) ; const { PrismaClient , Prisma } = require ( './node_modules/@prisma/client' ) ; const { prismaVersion , sql , raw , join , empty , PrismaClientValidationError , PrismaClientKnownRequestError } = Prisma ; const requests = [ ] ; const db = new PrismaClient ( { __internal : { useUds : true , hooks : { beforeRequest : ( request ) => requests . push ( request ) , } , } , } as any ) ; if ( ! prismaVersion || ! prismaVersion . client ) { throw new Error ( `prismaVersion missing: ${ JSON . stringify ( prismaVersion ) }` ) ; } await db . user . findMany ( ) ; const posts = await db . user . findUnique ( { where : { email : 'a@a.de' , } , } ) . posts ( ) ; expect ( posts . length ) . toBe ( 0 ) ; db . $disconnect ( ) ; expect ( requests . length ) . toBe ( 2 ) ; await db . user . findMany ( ) ; db . $disconnect ( ) ; expect ( requests . length ) . toBe ( 3 ) ; const count = await db . user . count ( ) ; expect ( typeof count === 'number' ) . toBe ( true ) ; const paramCount = await db . user . count ( { take : 10000 , } ) ; expect ( typeof paramCount === 'number' ) . toBe ( true ) ; db . $connect ( ) ; await db . $disconnect ( ) ; await new Promise ( ( r ) => setTimeout ( r , 200 ) ) ; db . $connect ( ) ; const userPromise = db . user . findMany ( ) ; await userPromise ; await db . $disconnect ( ) ; await db . $connect ( ) ; /**
     * queryRaw
     */ const rawQuery = await db . $queryRawUnsafe ( 'SELECT 1' ) ; expect ( rawQuery [ 0 ] [ '1' ] ) . toBe ( 1 ) ; const rawQueryWithValues = await db . $queryRawUnsafe ( 'SELECT $1 AS name, $2 AS id' , 'Alice' , 42 ) ; expect ( rawQueryWithValues [ 0 ] ) . toEqual ( { name : 'Alice' , id : 42 , } ) ; const rawQueryTemplate = await db . $queryRaw `SELECT 1` ; expect ( rawQueryTemplate [ 0 ] [ '1' ] ) . toBe ( 1 ) ; const rawQueryTemplateWithParams = await db . $queryRaw `SELECT * FROM User WHERE name = ${ 'Alice' }` ; expect ( rawQueryTemplateWithParams [ 0 ] . name ) . toBe ( 'Alice' ) ; const rawQueryTemplateFromSqlTemplate = await db . $queryRaw ( sql `
      SELECT ${ join ( [ raw ( 'email' ) , raw ( 'id' ) , raw ( 'name' ) ] ) }
      FROM ${ raw ( 'User' ) }
      ${ sql `WHERE name = ${ 'Alice' }` }
      ${ empty }
    ` ) ; expect ( rawQueryTemplateFromSqlTemplate [ 0 ] . name ) . toBe ( 'Alice' ) ; /**
     * .$executeRaw(
     */ const executeRaw = await db . $executeRawUnsafe ( 'UPDATE User SET name = $1 WHERE id = $2' , 'name' , 'id' ) ; expect ( executeRaw ) . toBe ( 0 ) ; const executeRawWithValues = await db . $executeRawUnsafe ( 'UPDATE User SET name = $1 WHERE id = $2' , 'Alice' , 'id' ) ; expect ( executeRawWithValues ) . toBe ( 0 ) ; const $executeRawTemplate = await db . $executeRaw `UPDATE User SET name = ${ 'name' } WHERE id = ${ 'id' }` ; expect ( $executeRawTemplate ) . toBe ( 0 ) ; let validationError ; try { await db . post . create ( { data : { } , } ) ; } catch ( e ) { validationError = e ; } if ( ! validationError || ! ( validationError instanceof PrismaClientValidationError ) ) { throw new Error ( `Validation error is incorrect` ) ; } let knownRequestError ; try { await db . user . create ( { data : { email : 'a@a.de' , name : 'Alice' , } , } ) ; } catch ( e ) { knownRequestError = e ; } if ( ! knownRequestError || ! ( knownRequestError instanceof PrismaClientKnownRequestError ) ) { throw new Error ( `Known request error is incorrect` ) ; } else { if ( ! knownRequestError . message . includes ( '.user.create()' ) ) { throw new Error ( `Invalid error: ${ knownRequestError . message }` ) ; } } const relationWhereNotNull = await db . user . findMany ( { where : { profile : { bio : { not : null } , } , } , } ) ; expect ( relationWhereNotNull ) . toEqual ( [ ] ) ; db . $disconnect ( ) ; } ) ;