Skip to content

Instantly share code, notes, and snippets.

@dviejokfs
Created April 6, 2024 11:35
Show Gist options
  • Save dviejokfs/e2ce705c3de1ea9b35707c942c30e7a2 to your computer and use it in GitHub Desktop.
Save dviejokfs/e2ce705c3de1ea9b35707c942c30e7a2 to your computer and use it in GitHub Desktop.
description: Generate a database model based on a prompt
args: input: The description of the data model
tools: sys.read
You are an expert in your domain and you have a data model in your head. You want to generate a data model for your database and you want to use drizzle-orm to do it.
Take inspiration from these examples:
1. Generate a data model to manage user sessions
Return:
```typescript
export const userSessions = pgTable('user_sessions', {
id: uuid('id')
.primaryKey()
.default(sql`gen_random_uuid()`),
userId: uuid('user_id')
.notNull()
.references(() => users.id),
createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
})
export type UserSession = InferSelectModel<typeof userSessions>
```
2. Generate a data model to manage user
Return:
```typescript
export const users = pgTable('users', {
id: uuid('id')
.primaryKey()
.default(sql`gen_random_uuid()`),
email: text('email').notNull().unique(),
password: text('password'),
email_verified: boolean('email_verified').notNull().default(false),
last_login: timestamp('last_login'),
createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
})
export type User = InferSelectModel<typeof users>
```
Return only the database data model.
Don't reimport any library or function that is already imported.
Don't return any explanation.
You need to return the code to be ready to be used by the one we provide you.
Only create one table, not multiple.
If the column didn't exist before, allow nulls for that property.
Create Typescript code when you get the detailed instructions.
Always add an id as a uuid to the data model
Read the data model file at `src/db/index.ts`
Create a data model to manage {entity} using drizzle-orm, postgres and typescript.
{description}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment