36 lines
805 B
TypeScript
36 lines
805 B
TypeScript
// Database models — the source of truth. `wrnexus db new --from-models` generates
|
|
// migrations from these, and query results are mapped back through them.
|
|
import { v, table } from "@wrnexus/db";
|
|
|
|
export type User = {
|
|
id: number;
|
|
email: string;
|
|
name: string;
|
|
active: boolean;
|
|
passwordHash: string;
|
|
createdAt: Date;
|
|
};
|
|
|
|
export const users = table<User>("users", {
|
|
id: v.id(),
|
|
email: v.string().unique(),
|
|
name: v.string(),
|
|
active: v.boolean().default(true),
|
|
passwordHash: v.string().default(""),
|
|
createdAt: v.timestamp().default("now"),
|
|
});
|
|
|
|
export type Post = {
|
|
id: number;
|
|
userId: number;
|
|
title: string;
|
|
body: string;
|
|
};
|
|
|
|
export const posts = table<Post>("posts", {
|
|
id: v.id(),
|
|
userId: v.int().references("users", "id"),
|
|
title: v.string(),
|
|
body: v.string(),
|
|
});
|