Back to Drizzle Orm

CreateTable

src/mdx/get-started/cockroach/CreateTable.mdx

latest438 B
Original Source

Create a schema.ts file in the src/db directory and declare your table:

typescript
import { int4, cockroachTable, varchar } from "drizzle-orm/cockroach-core";

export const usersTable = cockroachTable("users", {
  id: int4().primaryKey().generatedAlwaysAsIdentity(),
  name: varchar({ length: 255 }).notNull(),
  age: int4().notNull(),
  email: varchar({ length: 255 }).notNull().unique(),
});