adelsz / pgtyped

pgTyped - Typesafe SQL in TypeScript
https://pgtyped.dev
MIT License
2.91k stars 94 forks source link

Outer joins not recognized as nullable types #551

Open FrankHeijden opened 9 months ago

FrankHeijden commented 9 months ago

Describe the bug It seems from a previous issue that outer joins should be recognized as nullable, but in ^2.3.0 I cannot seem to replicate this behaviour.

Test case tables.sql:

-- CreateTable
CREATE TABLE "A" (
    "id" SERIAL NOT NULL,
    "aStr" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "B" (
    "aId" INTEGER NOT NULL,
    "bStr" TEXT NOT NULL,

    CONSTRAINT "B_pkey" PRIMARY KEY ("aId")
);

-- AddForeignKey
ALTER TABLE "B" ADD CONSTRAINT "B_aId_fkey" FOREIGN KEY ("aId") REFERENCES "A"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

test.sql:

/* @name get */
SELECT a.*, b."bStr" FROM "A" a
LEFT JOIN public."B" b on a.id = b."aId";

The generated type for this query is:

/** 'Get' return type */
export interface IGetResult {
  aStr: string;
  bStr: string;
  id: number;
}

But I'd expect the following:

/** 'Get' return type */
export interface IGetResult {
  aStr: string;
  bStr: string | null;
  id: number;
}