nextjs-saaskit
Version:
A Nextjs SaaS kit
29 lines (24 loc) • 999 B
text/typescript
import { sql } from 'drizzle-orm';
import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
export const usersTable = sqliteTable('users', {
id: integer('id').primaryKey(),
name: text('name').notNull(),
age: integer('age').notNull(),
email: text('email').unique().notNull(),
});
export const postsTable = sqliteTable('posts', {
id: integer('id').primaryKey(),
title: text('title').notNull(),
content: text('content').notNull(),
userId: integer('user_id')
.notNull()
.references(() => usersTable.id, { onDelete: 'cascade' }),
createdAt: text('created_at')
.default(sql`(CURRENT_TIMESTAMP)`)
.notNull(),
updateAt: integer('updated_at', { mode: 'timestamp' }).$onUpdate(() => new Date()),
});
export type InsertUser = typeof usersTable.$inferInsert;
export type SelectUser = typeof usersTable.$inferSelect;
export type InsertPost = typeof postsTable.$inferInsert;
export type SelectPost = typeof postsTable.$inferSelect;