drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
23.24k stars 565 forks source link

[BUG]:drizzle typescript doesn't see boolean column #2900

Open Kaidstor opened 2 weeks ago

Kaidstor commented 2 weeks ago

What version of drizzle-orm are you using?

0.33.0

What version of drizzle-kit are you using?

0.24.2

Describe the Bug

i have entity

export const db_ranges = pgTable('ranges', {
  id: serial('id').primaryKey(),
  fromIp: varchar('fromIp', { length: 20 }).notNull(),
  toIp: varchar('toIp', { length: 20 }).notNull(),
  createdAt: timestamp('createdAt').notNull(),
  active: boolean('active').notNull().default(true),
});

but when try to update it

 await db
    .update(db_ranges)
    .set({ active: false })
     where(eq(db_ranges.id, id));

see the error: Object literal may only specify known properties, and 'active' does not exist in type '{ createdAt?: SQL | Date; country_code?: string | SQL; fromIp?: string | SQL; toIp?: string | SQL; }'.ts(2353)

Expected behavior

expect that I can to change boolean value and it contains in the ranges

Environment & setup

No response

cayasso commented 1 week ago

Getting this exact same problem, its started since drizzle-orm@0.32.0

tamagokun commented 1 day ago

Same thing here, seems like the typescript types are wonky all of a sudden. Same error, different schema:

// schema.ts
export const event = sqliteTable(
  "Event",
  {
    id: text("id").primaryKey(),
    projectId: integer("projectId")
      .notNull()
      .references(() => project.id),
    type: text("type", { enum: ["EXCEPTION", "MESSAGE"] }).notNull(),
    message: text("message"),
    stack: text("stack", { mode: "json" }),
    meta: text("meta", { mode: "json" }),
    count: integer("count"),
    createdAt: text("createdAt").default(sql`(CURRENT_TIMESTAMP)`),
    lastEventAt: text("lastEventAt").default(sql`(CURRENT_TIMESTAMP)`),
    resolvedAt: text("resolvedAt"),
  },
  (table) => {
    return {
      projectIdx: index("projectIdx").on(table.projectId),
    };
  }
);
import { db, schema } from "../../../../../db";
import { and, eq } from "drizzle-orm";

await db
    .update(schema.event)
    .set({ resolvedAt: new Date().toISOString() })
    .where(
      and(
        eq(schema.event.id, String(eventId)),
        eq(schema.event.projectId, Number(projectId))
      )
    );
Object literal may only specify known properties, and 'resolvedAt' does not exist in type '{ projectId?: number | SQL<unknown>; id?: string | SQL<unknown>; type?: SQL<unknown> | "EXCEPTION" | "MESSAGE"; }'.ts(2353)

in a different file, typescript errors over the count column, and in another file, it errors over the id column. Doesn't seem to matter what column or column type, just any column when trying to make an update using set, or an insert using values