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

[FEATURE]: Add documentation in Goodies on how to get materialized view (or view) columns for select #2153

Open
pencilcheck opened this issue Apr 12, 2024 · 2 comments
Labels
docs/improvements docs Improvements or additions to documentation

Comments

@pencilcheck
Copy link

Describe what you want

const columns = getMaterializedViewConfig(materializedView).selectedFields;

We have a section to show how to get the select columns for pg table but not views nor materialized view. If someone can add the example using the code above that would be awesome.

@pencilcheck pencilcheck added the enhancement New feature or request label Apr 12, 2024
@realmikesolo realmikesolo added the docs Improvements or additions to documentation label Apr 12, 2024
@brncsk
Copy link

brncsk commented Aug 27, 2024

For anyone looking for a way to infer a matview's select model, this is the way to go:

import type { InferModelFromColumns } from 'drizzle-orm';

export type MatViewSelectModel<M extends PgMaterializedView<string, any, Record<string, PgColumn>>> =
  InferModelFromColumns<M['_']['selectedFields'], 'select'>;

// Usage:
declare const matView: PgMaterializedView<string, any, Record<string, PgColumn>>; // <- this should be your matview object defined using `pgMaterializedView()`
type M = MatViewSelectModel<typeof matView>;

@L-Mario564 L-Mario564 added docs/improvements and removed enhancement New feature or request labels Oct 21, 2024
@juliomuhlbauer
Copy link

juliomuhlbauer commented Nov 2, 2024

For anyone looking for a way to infer a matview's select model, this is the way to go:

import type { InferModelFromColumns } from 'drizzle-orm';

export type MatViewSelectModel<M extends PgMaterializedView<string, any, Record<string, PgColumn>>> =
  InferModelFromColumns<M['_']['selectedFields'], 'select'>;

// Usage:
declare const matView: PgMaterializedView<string, any, Record<string, PgColumn>>; // <- this should be your matview object defined using `pgMaterializedView()`
type M = MatViewSelectModel<typeof matView>;

This does not work with aliased columns: https://drizzle.run/piy3qe6lr8d7eanurd3q191u

Issue: #3392

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs/improvements docs Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

5 participants