Skip to content

Commit

Permalink
feat(types): add TableSelector type
Browse files Browse the repository at this point in the history
This type is useful when wrapping `db.select` with a function that accepts a caller-defined selector function.

Note: There was already an internal TableSelector type, which has been renamed to TableSelect.
  • Loading branch information
aleclarson committed Sep 14, 2022
1 parent 12f4608 commit e22d278
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/postgres/table.ts
Expand Up @@ -71,7 +71,7 @@ export interface TableRef<
PrimaryKey extends string = any,
NullableColumn extends string = any
> extends TableType<T, TableName, PrimaryKey, NullableColumn>,
TableSelector<T, TableName, PrimaryKey, NullableColumn> {
TableSelect<T, TableName, PrimaryKey, NullableColumn> {
/**
* Exclude specific columns from the result set.
*/
Expand All @@ -80,7 +80,20 @@ export interface TableRef<
): Selection<Omit<T, Omitted[number]>, this>
}

type TableSelector<
/**
* The callback type used for selecting columns from a table.
*
* Use this to wrap a `db.select` call while still allowing a
* custom selector to be used.
*/
export type TableSelector<
Selected extends RawSelection,
From extends TableRef
> = (
row: From extends TableRef<infer T, any, infer PK> ? ColumnRefs<T, PK> : never
) => Narrow<Selected>

type TableSelect<
T extends object,
TableName extends string,
PrimaryKey extends string,
Expand Down

0 comments on commit e22d278

Please sign in to comment.