Help, Partial select with drizzle-zod

// schema
 const usersTable = pgTable("users", {
  id: varchar("id", { length: 256 })
    .primaryKey()
    .notNull()
    .$defaultFn(() => createId()),
  name: varchar("name", { length: 256 }).notNull(),
  createdAt: timestamp("created_at").defaultNow().notNull()
});

// drizzle-zod
const SelectUser = createSelectSchema(usersTable);
const SelectUserById = SelectUser.pick({ id: true });

export type TSelectUserById = z.infer<typeof SelectUserById>;

function getUserById (input: TSelectUserById) {
  const result = await db.select({ id: input.id }).from(usersTable);
  return result;
}


Type 'string' is not assignable to type 'SQL<unknown> | Aliased<unknown> | PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}> | PgTable<TableConfig> | SelectedFieldsFlat<...>'.ts(2322)
Screenshot_2024-02-22_at_9.23.42_AM.png
Was this page helpful?