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

docs: use the new pgTable signature instead deprecated #433

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/content/docs/indexes-constraints.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,18 @@ A `PRIMARY KEY` constraint automatically has a `UNIQUE` constraint.
export const composite = pgTable('composite_example', {
id: integer('id'),
name: text('name'),
}, (t) => ({
}, (t) => [{
unq: unique().on(t.id, t.name),
unq2: unique('custom_name').on(t.id, t.name)
}));
}]);

// In Postgres 15.0+ NULLS NOT DISTINCT is available
// This example demonstrates both available usages
export const userNulls = pgTable('user_nulls_example', {
id: integer('id').unique("custom_name", { nulls: 'not distinct' }),
}, (t) => ({
}, (t) => [{
unq: unique().on(t.id).nullsNotDistinct()
}));
}]);
```

```sql
Expand Down Expand Up @@ -331,9 +331,9 @@ If you define a `CHECK` constraint on a table it can limit the values in certain
username: text().notNull(),
age: integer(),
},
(table) => ({
(table) => [{
checkConstraint: check("age_check1", sql`${table.age} > 21`),
})
}]
);
```
```sql
Expand Down Expand Up @@ -520,10 +520,10 @@ Drizzle ORM provides a standalone `primaryKey` operator for that:
authorId: integer("author_id"),
bookId: integer("book_id"),
}, (table) => {
return {
return [{
pk: primaryKey({ columns: [table.bookId, table.authorId] }),
pkWithCustomName: primaryKey({ name: 'custom_name', columns: [table.bookId, table.authorId] }),
};
}];
});
```

Expand Down Expand Up @@ -701,13 +701,13 @@ set return type for reference callback or use a standalone `foreignKey` operator
name: text("name"),
parentId: integer("parent_id"),
}, (table) => {
return {
return [{
parentReference: foreignKey({
columns: [table.parentId],
foreignColumns: [table.id],
name: "custom_fk"
}),
};
}];
});
```

Expand Down Expand Up @@ -787,13 +787,13 @@ To declare multicolumn foreign keys you can use a dedicated `foreignKey` operato
userFirstName: text("user_first_name"),
userLastName: text("user_last_name"),
}, (table) => {
return {
return [{
userReference: foreignKey({
columns: [table.userFirstName, table.userLastName],
foreignColumns: [user.firstName, user.lastName]
name: "custom_fk"
})
}
}]
})
```

Expand Down