Help, Partial select with drizzle-zod
// schema
// drizzle-zod
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)