Skip to main content

Create a Model

To create a model add @table to a model in your lib/schema.tsp. We also use @id to identify the identity column and @uuid to identifiy the column as a uuid type.

import "@skibididrizz/drizzle";
using Drizzle;

@table model Blog {
@uuid @id id: string;
name: string;
description?:string;
};

Will result in a drizzle/schema.ts like:

import { pgTable, text } from "drizzle-orm/pg-core";

export const BlogTable = pgTable("Blog", {
id: uuid("id").defaultRandom().primaryKey(),
name: text("name").notNull(),
description: text("description"),
});

export type Blog = typeof BlogTable.$inferSelect;

Naming

Renaming the table in lib/schema.tsp will change the name of the table and the type. You can use @map annotation to rename columns, and the @table annotation to rename the table. In addition for default values can be site by assignment syntax.

import "@skibididrizz/drizzle";
using Drizzle;

@table("blogs") model Blog {
@map("_id") @uuid @id id: string;
@map("label") name: string;
@map("note") description?: string;
};

Will result in a drizzle/schema.ts like:

import { pgTable, text } from "drizzle-orm/pg-core";

export const BlogTable = pgTable("blogs", {
id: uuid("_id").defaultRandom().primaryKey(),
name: text("label").notNull(),
description: text("note"),
});

export type Blog = typeof BlogTable.$inferSelect;