Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Example for Defining Composite Primary Keys #456

Open
farhadham opened this issue Dec 11, 2024 · 0 comments · May be fixed by #457 or #453
Open

Incorrect Example for Defining Composite Primary Keys #456

farhadham opened this issue Dec 11, 2024 · 0 comments · May be fixed by #457 or #453

Comments

@farhadham
Copy link

farhadham commented Dec 11, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant