Skip to content

Commit

Permalink
fix(client): allow pick as model name (#5122)
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Jan 15, 2021
1 parent 9c11e19 commit 85e4a2e
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 6 deletions.
Expand Up @@ -881,18 +881,25 @@ export namespace Prisma {
*/
export type PromiseReturnType<T extends (...args: any) => Promise<any>> = PromiseType<ReturnType<T>>

/**
* From T, pick a set of properties whose keys are in the union K
*/
type Prisma__Pick<T, K extends keyof T> = {
[P in K]: T[P];
};


export type Enumerable<T> = T | Array<T>;

export type RequiredKeys<T> = {
[K in keyof T]-?: {} extends Pick<T, K> ? never : K
[K in keyof T]-?: {} extends Prisma__Pick<T, K> ? never : K
}[keyof T]

export type TruthyKeys<T> = {
[key in keyof T]: T[key] extends false | undefined | null ? never : key
}[keyof T]

export type TrueKeys<T> = TruthyKeys<Pick<T, RequiredKeys<T>>>
export type TrueKeys<T> = TruthyKeys<Prisma__Pick<T, RequiredKeys<T>>>

/**
* Subset
Expand Down Expand Up @@ -1084,7 +1091,7 @@ export namespace Prisma {
/**
* Like \`Pick\`, but with an array
*/
type PickArray<T, K extends Array<keyof T>> = Pick<T, TupleToUnion<K>>
type PickArray<T, K extends Array<keyof T>> = Prisma__Pick<T, TupleToUnion<K>>

class PrismaClientFetcher {
private readonly prisma;
Expand Down
33 changes: 33 additions & 0 deletions src/packages/client/src/__tests__/types/pick/schema.prisma
@@ -0,0 +1,33 @@
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}

model Pick {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
title String
content String?
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id])
authorId Int
}

model Profile {
id Int @id @default(autoincrement())
bio String?
user User @relation(fields: [userId], references: [id])
userId Int @unique
}

model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Pick[]
profile Profile?
}
18 changes: 18 additions & 0 deletions src/packages/client/src/__tests__/types/pick/test.ts
@@ -0,0 +1,18 @@
import { PrismaClient } from '@prisma/client'

async function main() {
const prisma = new PrismaClient()

const data = await prisma.pick.findFirst({
include: {
author: true,
},
})

data?.author.id

console.log(data)
prisma.$disconnect()
}

main()
8 changes: 8 additions & 0 deletions src/packages/client/src/__tests__/types/pick/tsconfig.json
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"strict": true,
"esModuleInterop": true
}
}
13 changes: 10 additions & 3 deletions src/packages/client/src/generation/TSClient/common.ts
Expand Up @@ -194,18 +194,25 @@ export type PromiseType<T extends PromiseLike<any>> = T extends PromiseLike<infe
*/
export type PromiseReturnType<T extends (...args: any) => Promise<any>> = PromiseType<ReturnType<T>>
/**
* From T, pick a set of properties whose keys are in the union K
*/
type Prisma__Pick<T, K extends keyof T> = {
[P in K]: T[P];
};
export type Enumerable<T> = T | Array<T>;
export type RequiredKeys<T> = {
[K in keyof T]-?: {} extends Pick<T, K> ? never : K
[K in keyof T]-?: {} extends Prisma__Pick<T, K> ? never : K
}[keyof T]
export type TruthyKeys<T> = {
[key in keyof T]: T[key] extends false | undefined | null ? never : key
}[keyof T]
export type TrueKeys<T> = TruthyKeys<Pick<T, RequiredKeys<T>>>
export type TrueKeys<T> = TruthyKeys<Prisma__Pick<T, RequiredKeys<T>>>
/**
* Subset
Expand Down Expand Up @@ -397,7 +404,7 @@ type MaybeTupleToUnion<T> = T extends any[] ? TupleToUnion<T> : T
/**
* Like \`Pick\`, but with an array
*/
type PickArray<T, K extends Array<keyof T>> = Pick<T, TupleToUnion<K>>
type PickArray<T, K extends Array<keyof T>> = Prisma__Pick<T, TupleToUnion<K>>
${
!hideFetcher
Expand Down

0 comments on commit 85e4a2e

Please sign in to comment.