Prisma 客户端未将 属性 标记为空

Prisma client not marking property as null

我使用的是 Prisma 3.8.1 版。 Prisma 客户端不会在 TS 中将 User.oauthData 属性 标记为可空。有人可以帮忙吗? Prisma 架构和生成的 SQL 个文件如下:

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider = "prisma-client-js"
  binaryTargets = ["native", "rhel-openssl-1.0.x"]
}

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

model Account {
  id BigInt @id
  createdAt DateTime @db.Timestamptz(3) @default(now())
  updatedAt DateTime @db.Timestamptz(3) @updatedAt
  name String
  users User[]
}

model User {
  id BigInt @id
  createdAt DateTime @db.Timestamptz(3) @default(now())
  updatedAt DateTime @db.Timestamptz(3) @updatedAt
  accountId BigInt
  account Account @relation(fields: [accountId], references: [id])
  fullName String
  email String
  oauthData Json?
}

-- CreateTable
CREATE TABLE "Account" (
    "id" BIGINT NOT NULL,
    "createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMPTZ(3) NOT NULL,
    "name" TEXT NOT NULL,

    CONSTRAINT "Account_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "User" (
    "id" BIGINT NOT NULL,
    "createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMPTZ(3) NOT NULL,
    "accountId" BIGINT NOT NULL,
    "fullName" TEXT NOT NULL,
    "email" TEXT NOT NULL,
    "oauthData" JSONB,

    CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "User" ADD CONSTRAINT "User_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "Account"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

我使用的是 Prisma 3.8.1 版。 Prisma 客户端不会在 TS 中将 User.oauthData 属性 标记为可空。有人可以帮忙吗? Prisma 架构和生成的 SQL 个文件如下:

使用 JSONB 字段时,允许有两种类型的空值:JSON 空值和 DB 空值。

这在 the Prisma docs for working with JSON fields 中有更详细的解释。

为了避免数据库允许的两种类型 null 之间的这种歧义,我们允许以下两个值之一:

  • Prisma.DbNull: 数据库中的值为NULL。
  • Prisma.JsonNull: 数据库中的值包含一个 JSON 值为空的值。

这就是这两个空值在数据库中的样子(与您共享的架构相同):

prisma-script> select id, "oauthData" from "User"
+---------+-------------+
| id      | oauthData   |
|---------+-------------|
| 124124  | null        |
| 1241241 | <null>      |
+---------+-------------+

您还可以在模型的生成类型中看到这一点 User