© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago
rykuno

Custom `Select` object returns type `any`

Databases like Planetscale do not support FK constraints. As I understand I can manipulate the returned data structure from within the
select
select
clause.

The data structure returned is correct but there is a typescript error casting it to any. Is there a way to fix this or am I misusing select?

  const [event] = await db
    .select({
      ...events,
      createdBy: {
        ...users
      }
    })
    .from(events)
    .innerJoin(users, eq(events.createdByUserId, users.id))
    .where(eq(events.id, params.id));
  const [event] = await db
    .select({
      ...events,
      createdBy: {
        ...users
      }
    })
    .from(events)
    .innerJoin(users, eq(events.createdByUserId, users.id))
    .where(eq(events.id, params.id));


export const events = mysqlTable("events", {
  id: cuid2("id").primaryKey().notNull(),
  name: text("name").notNull(),
  description: text("description"),
  image: text("image").notNull(),
  privacy: text("privacy", { enum: ["public", "private"] }).notNull(),
  startDate: timestamp("startDate").notNull(),
  endDate: timestamp("endDate").notNull(),
  createdByUserId: cuid2("created_by_user_id").notNull(),
  created_at: timestamp("created_at").notNull().defaultNow(),
  updated_at: timestamp("updated_at").notNull().defaultNow().onUpdateNow()
});
export const events = mysqlTable("events", {
  id: cuid2("id").primaryKey().notNull(),
  name: text("name").notNull(),
  description: text("description"),
  image: text("image").notNull(),
  privacy: text("privacy", { enum: ["public", "private"] }).notNull(),
  startDate: timestamp("startDate").notNull(),
  endDate: timestamp("endDate").notNull(),
  createdByUserId: cuid2("created_by_user_id").notNull(),
  created_at: timestamp("created_at").notNull().defaultNow(),
  updated_at: timestamp("updated_at").notNull().defaultNow().onUpdateNow()
});
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

[object Object] on custom type
Drizzle TeamDTDrizzle Team / help
2y ago
Get type from select object ?
Drizzle TeamDTDrizzle Team / help
2y ago
db.query returns empty object
Drizzle TeamDTDrizzle Team / help
2y ago
inferInsert returns unexpected type?
Drizzle TeamDTDrizzle Team / help
14mo ago