Select statement with dynamic fields

Hello I'm writing out this because I don't get how I'm supposed to pass a subset of a given table's fields to a select() statement.

I would like to do something like this:
getUserById(id: number, fields: ??? = ['*'])  => {
  const [user] = await drizzle.select(fields).from(usersTable).where(eq(usersTable.id, id));
}


I would like to call that function like this:
getUserById(1, ['id', 'name']);

If second parameter is ommited then i get all columns (with the default ['*'] or something like that)

I tried several approches, and it seems like i need to use SelectedFields but I don't understand how to do so. I would assume that the secont type argument is typeof userTable but cannot find what to put as first one.
Was this page helpful?