© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
2 replies
glennvoid

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()
});
 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;
}
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)
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
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Help with Drizzle-zod
Drizzle TeamDTDrizzle Team / help
3y ago
select and alter columns with drizzle-zod
Drizzle TeamDTDrizzle Team / help
3y ago
help with drizzle-zod with jsonb column
Drizzle TeamDTDrizzle Team / help
3y ago
Drizzle-zod combined with regular zod? 🙃
Drizzle TeamDTDrizzle Team / help
15mo ago