Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PG] Add missing select functions in with clause #1467

Closed
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion drizzle-orm/src/pg-core/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,37 @@ export class PgDatabase<
});
}

return { select };
function selectDistinct(): PgSelectBuilder<undefined>;
function selectDistinct<TSelection extends SelectedFields>(fields: TSelection): PgSelectBuilder<TSelection>;
function selectDistinct(fields?: SelectedFields): PgSelectBuilder<SelectedFields | undefined> {
return new PgSelectBuilder({
fields: fields ?? undefined,
session: self.session,
dialect: self.dialect,
withList: queries,
distinct: true,
});
}

function selectDistinctOn(on: (PgColumn | SQLWrapper)[]): PgSelectBuilder<undefined>;
function selectDistinctOn<TSelection extends SelectedFields>(
on: (PgColumn | SQLWrapper)[],
fields: TSelection,
): PgSelectBuilder<TSelection>;
function selectDistinctOn(
on: (PgColumn | SQLWrapper)[],
fields?: SelectedFields,
): PgSelectBuilder<SelectedFields | undefined> {
return new PgSelectBuilder({
fields: fields ?? undefined,
session: self.session,
dialect: self.dialect,
withList: queries,
distinct: { on },
});
}

return { select, selectDistinct, selectDistinctOn };
}

select(): PgSelectBuilder<undefined>;
Expand Down