My database schema is structured like so:
export const Organization = pgTable(
"Organization",
{
id: text("id").primaryKey().notNull(),
name: text("name").notNull(),
createdAt: timestamp("createdAt", { precision: 3, mode: "string" })
.defaultNow()
.notNull(),
updatedAt: timestamp("updatedAt", {
precision: 3,
mode: "string",
}).notNull(),
},
(table) => {
return {
name_key: uniqueIndex("Organization_name_key").using(
"btree",
table.name,
),
};
},
);
However, when attempting to execute a query on it:
import * as schema from "../src/drizzle/schema";
import { Client } from "pg";
export const client = new Client({
connectionString: process.env.DATABASE_URL,
});
export const db = drizzle(client, { schema });
await db.insert(Organization).values({
id: "68184833-8d03-41d6-95a2-4f23c4f097d6",
name: "org",
createdAt: new Date(),
updatedAt: new Date(),
});
The error message in TypeScript states that the data is incorrect:
Object literal may only specify known properties, and 'id' does not exist in type '{ id: string | SQL<unknown> | Placeholder<string, any>; ...
When appending as any
at the end, it resolves the issue. However, I prefer to maintain type safety. What am I missing here?