This commit is contained in:
JOLIMAITRE Matthieu 2024-05-21 18:49:16 +02:00
commit 60133a4a08
23 changed files with 529 additions and 0 deletions

9
storage/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(),
});

58
storage/store.ts Normal file
View file

@ -0,0 +1,58 @@
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";
import mimeDbV1520 from "$std/media_types/vendor/mime-db.v1.52.0.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"],
},
},
});