Skip to content

Commit

Permalink
Add isView util function
Browse files Browse the repository at this point in the history
  • Loading branch information
L-Mario564 committed Nov 15, 2024
1 parent d91df79 commit bbaf6f0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drizzle-orm/src/sql/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,8 @@ export function fillPlaceholders(params: unknown[], values: Record<string, unkno

export type ColumnsSelection = Record<string, unknown>;

const IsDrizzleView = Symbol.for('drizzle:IsDrizzleView');

export abstract class View<
TName extends string = string,
TExisting extends boolean = boolean,
Expand All @@ -636,6 +638,9 @@ export abstract class View<
isAlias: boolean;
};

/** @internal */
[IsDrizzleView] = true;

declare readonly $inferSelect: InferSelectViewModel<View<Assume<TName, string>, TExisting, TSelection>>;

constructor(
Expand All @@ -662,6 +667,10 @@ export abstract class View<
}
}

export function isView(view: unknown): view is View {
return typeof view === 'object' && view !== null && IsDrizzleView in view;
}

export type InferSelectViewModel<TView extends View> =
Equal<TView['_']['selectedFields'], { [x: string]: unknown }> extends true ? { [x: string]: unknown }
: SelectResult<
Expand Down

0 comments on commit bbaf6f0

Please sign in to comment.