This works, however I'd like to be able to select only the view columns. For tables, we have the help of getTableColumns(), which is defined in the source code as:
export function getTableColumns<T extends Table>(table: T): T['_']['columns'] { return table[Table.Symbol.Columns];}
export function getTableColumns<T extends Table>(table: T): T['_']['columns'] { return table[Table.Symbol.Columns];}
I couldn't find an equivalent for views. So I tried writing my own
getViewColumns()
getViewColumns()
function. Here's my attempt:
import { View } from 'drizzle-orm';export function getViewColumns<V extends View>(view : V): V['_']['selectedFields'] { return view[View.Symbol.SelectedFields]; // error on this line}
import { View } from 'drizzle-orm';export function getViewColumns<V extends View>(view : V): V['_']['selectedFields'] { return view[View.Symbol.SelectedFields]; // error on this line}
Which is definitely incorrect, but I'm stuck. Any ideas on how one could write a working
getViewColumns()
getViewColumns()
function? I'm connecting to a PostgreSQL database, and the view is an existing, regular (non-materialized) view, if it makes a difference.