-
Notifications
You must be signed in to change notification settings - Fork 348
Description
The current documentation on the Drizzle ORM website provides an incorrect example for defining composite primary keys for postgreSQL
using the primaryKey operator. Specifically, the example adds the primaryKey definitions inside an object with keys pk and pkWithCustomName, which does not align with the correct syntax.
Current Example:
export const booksToAuthors = pgTable("books_to_authors", {
authorId: integer("author_id"),
bookId: integer("book_id"),
}, (table) => {
return [{
pk: primaryKey({ columns: [table.bookId, table.authorId] }),
pkWithCustomName: primaryKey({ name: 'custom_name', columns: [table.bookId, table.authorId] }),
}];
});
Expected Example (Correct):
export const booksToAuthors = pgTable(
"books_to_authors",
{
authorId: integer("author_id"),
bookId: integer("book_id"),
},
(table) => {
return [
primaryKey({ columns: [table.bookId, table.authorId] }),
primaryKey({ name: "custom_name", columns: [table.bookId, table.authorId] }),
];
},
);
The current example may mislead developers into defining composite primary keys incorrectly, resulting in potential runtime errors or unexpected behavior when working with Drizzle ORM.
Metadata
Metadata
Assignees
Labels
No labels