Skip to content

Conversation

@Bas950
Copy link

@Bas950 Bas950 commented Jul 7, 2023

On for example FULL joins, it currently returns the response objects as NULL when the first column in the response is NULL.
This should only happen when the full response object only has NULL values.

In the following example the response you get is the following:
[ { test_table: null, test_table2: null } ]

With my fix:

[
  {
    test_table: { nullValue: null, id: 1 },
    test_table2: { name: null, id: 123, testTableId: 1 }
  }
]
import { pgTable, text, serial } from "drizzle-orm/pg-core";
import { drizzle } from "drizzle-orm/node-postgres";
import pg from "pg";
import { eq } from "drizzle-orm";

const { Client } = pg;

(async () => {
	const testTable = pgTable("test_table", {
		nullValue: text("null_value"),
		id: serial("id")
	});

	const table2 = pgTable("test_table2", {
		name: text("name"),
		id: serial("id"),
		testTableId: serial("test_table_id")
	});

	const client = new Client(
		"postgres://postgres:postgres@localhost:5432/postgres"
	);
	const db = drizzle(client);

	await client.connect();

	await client.query(`
		CREATE TABLE IF NOT EXISTS test_table (
			null_value TEXT,
			id SERIAL PRIMARY KEY
		);

		CREATE TABLE IF NOT EXISTS test_table2 (
			name TEXT,
			id SERIAL PRIMARY KEY,
			test_table_id INTEGER REFERENCES test_table(id)
		);

		INSERT INTO test_table (id) VALUES (1);

		INSERT INTO test_table2 (id, test_table_id) VALUES (123, 1);
	`);

	console.log(
		await db
			.select()
			.from(testTable)
			.fullJoin(table2, eq(testTable.id, table2.testTableId))
			.execute()
	);

	await client.query(`
		DROP TABLE IF EXISTS test_table2;
		DROP TABLE IF EXISTS test_table;
	`);

	await client.end();
})();
@Bas950
Copy link
Author

Bas950 commented Jul 7, 2023

Added a reproduction example.

@dankochetov dankochetov self-requested a review August 29, 2023 18:00
Copy link
Contributor

@dankochetov dankochetov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test that verifies this behavior?

@Bas950
Copy link
Author

Bas950 commented Aug 29, 2023

I added a test, but not sure if it works as it seems like I am unable to build...

@AndriiSherman
Copy link
Member

I added a test, but not sure if it works as it seems like I am unable to build...

What is not working for you? I can try to help you with build process

@AndriiSherman
Copy link
Member

I added a test, but not sure if it works as it seems like I am unable to build...

What is not working for you? I can try to help you with build process

Will check in pipeline here as well

@Bas950
Copy link
Author

Bas950 commented Sep 4, 2023

I added a test, but not sure if it works as it seems like I am unable to build...

What is not working for you? I can try to help you with build process

Will check in pipeline here as well

Looks like the pipelines passed, so I guess it's fine.

@Bas950 Bas950 requested a review from dankochetov September 4, 2023 17:35
@Bas950
Copy link
Author

Bas950 commented Dec 3, 2023

@dankochetov / @AndriiSherman Any updates on the review status?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants