drizzle-team / drizzle-team/drizzle-orm-docs

Incorrect Example for Defining Composite Primary Keys

Open
#456 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
MDX
Stars
241
Forks
401
Avg merge
5h 44m
Merged PRs (30d)
1

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:
```js
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):
```js
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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.