update patyhs

This commit is contained in:
JOLIMAITRE Matthieu 2024-05-23 21:22:09 +02:00
parent c70202e5d1
commit 0458ad4948
7 changed files with 9 additions and 13 deletions

9
lib/models/User.ts Normal file
View file

@ -0,0 +1,9 @@
import { z } from "https://deno.land/x/zod@v3.23.8/mod.ts";
export const UserModel = z.object({
id: z.string().uuid().describe("primary"),
name: z.string(),
email: z.string(),
password: z.string(),
pfp_url: z.string(),
});

57
lib/store.ts Normal file
View file

@ -0,0 +1,57 @@
import { createPentagon } from "https://deno.land/x/pentagon@v0.1.5/mod.ts";
import { project_root_dir } from "../utils.ts";
import { z } from "https://deno.land/x/zod@v3.21.4/mod.ts";
const kv = await Deno.openKv(project_root_dir() + "local/kv");
export type User = z.infer<typeof user_model>;
export const user_model = z.object({
id: z.string().uuid().describe("primary"),
name: z.string(),
email: z.string(),
password: z.string(),
pfp_url: z.string(),
like_set: z.set(z.string().uuid()),
});
export type Post = z.infer<typeof post_model>;
export const post_model = z.object({
id: z.string().uuid().describe("primary"),
title: z.string(),
content: z.string(),
date: z.number(),
like_count: z.number(),
author_id: z.string().uuid(),
});
export type Comment = z.infer<typeof comment_model>;
export const comment_model = z.object({
id: z.string().uuid().describe("primary"),
date: z.number(),
post_id: z.string().uuid(),
author_id: z.string().uuid(),
});
export const db = createPentagon(kv, {
users: {
schema: user_model,
relations: {
posts: ["posts", [post_model], "id", "author_id"],
comments: ["comments", [comment_model], "id", "author_id"],
},
},
posts: {
schema: post_model,
relations: {
author: ["users", user_model, "author_id", "id"],
comments: ["comments", [comment_model], "id", "post_id"],
},
},
comments: {
schema: comment_model,
relations: {
author: ["users", user_model, "author_id", "id"],
post: ["post", post_model, "post_id", "id"],
},
},
});