-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(client): Allow to use
Metric
as a model name
Problem: even though built-in `Metric` type is placed in a different namespace, type conflict still occurs: `Delegate` classes are in the same namespace and can't refer to non-namespaced name. Implements a tiny part of [namespace overhaul proposal](https://www.notion.so/prismaio/Fix-type-name-clashes-in-TS-Client-9e9bbdee13f94a818ece060e55465267): introduces `$Models` namespace. Ref #12469
- Loading branch information
Showing
10 changed files
with
1,317 additions
and
1,198 deletions.
There are no files selected for viewing
1,305 changes: 662 additions & 643 deletions
1,305
...client/src/__tests__/integration/happy/exhaustive-schema-mongo/__snapshots__/test.ts.snap
Large diffs are not rendered by default.
Oops, something went wrong.
1,100 changes: 558 additions & 542 deletions
1,100
packages/client/src/__tests__/integration/happy/exhaustive-schema/__snapshots__/test.ts.snap
Large diffs are not rendered by default.
Oops, something went wrong.
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
24 changes: 24 additions & 0 deletions
24
packages/client/tests/functional/naming-conflict/metric/_matrix.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,24 @@ | ||
import { defineMatrix } from '../../_utils/defineMatrix' | ||
|
||
export default defineMatrix(() => [ | ||
[ | ||
{ | ||
provider: 'sqlite', | ||
}, | ||
{ | ||
provider: 'postgresql', | ||
}, | ||
{ | ||
provider: 'mysql', | ||
}, | ||
{ | ||
provider: 'mongodb', | ||
}, | ||
{ | ||
provider: 'cockroachdb', | ||
}, | ||
{ | ||
provider: 'sqlserver', | ||
}, | ||
], | ||
]) |
21 changes: 21 additions & 0 deletions
21
packages/client/tests/functional/naming-conflict/metric/prisma/_schema.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,21 @@ | ||
import { idForProvider } from '../../../_utils/idForProvider' | ||
import testMatrix from '../_matrix' | ||
|
||
export default testMatrix.setupSchema(({ provider }) => { | ||
return /* Prisma */ ` | ||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
datasource db { | ||
provider = "${provider}" | ||
url = env("DATABASE_URI_${provider}") | ||
} | ||
model Metric { | ||
id ${idForProvider(provider)} | ||
name String | ||
value Int | ||
} | ||
` | ||
}) |
24 changes: 24 additions & 0 deletions
24
packages/client/tests/functional/naming-conflict/metric/tests.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,24 @@ | ||
import testMatrix from './_matrix' | ||
// @ts-ignore | ||
import type { PrismaClient } from './node_modules/@prisma/client' | ||
|
||
declare let prisma: PrismaClient | ||
|
||
testMatrix.setupTestSuite(() => { | ||
test('allows to use Metric name for a model', async () => { | ||
await prisma.metric.create({ | ||
data: { | ||
name: 'signups', | ||
value: 9000, | ||
}, | ||
}) | ||
|
||
const metric = await prisma.metric.findFirst() | ||
|
||
expect(metric).toEqual({ | ||
id: expect.any(String), | ||
name: 'signups', | ||
value: 9000, | ||
}) | ||
}) | ||
}) |