打算使用prisma

This commit is contained in:
2025-11-13 10:30:28 +08:00
parent 94d570557b
commit adcb7920bd
11 changed files with 10794 additions and 15979 deletions

View File

@@ -1,11 +1,23 @@
"use server";
import { UserController } from "./db";
import { createTextPair } from "./controllers/TextPairController";
export async function loginAction(formData: FormData) {
const username = formData.get("username")?.toString();
const password = formData.get("password")?.toString();
if (username && password) await UserController.createUser(username, password);
}
async function createTextPairAction(formData: FormData) {
'use server';
const textPair = {
text1: formData.get('text1') as string,
text2: formData.get('text2') as string,
locale1: formData.get('locale1') as string,
locale2: formData.get('locale2') as string,
folderId: parseInt(formData.get('folderId') as string)
}
if(textPair.text1 && textPair.text2 && textPair.locale1 && textPair.locale2 && textPair.folderId){
await createTextPair(
textPair.locale1,
textPair.locale2,
textPair.text1,
textPair.text2,
textPair.folderId
);
}
}

View File

@@ -21,6 +21,17 @@ export async function getFoldersByOwner(owner: string) {
}
}
export async function getOwnerByFolderId(id: number) {
try {
const owner = await pool.query("SELECT owner FROM folders WHERE id = $1", [
id,
]);
return owner.rows[0].owner;
} catch (e) {
console.log(e);
}
}
export async function getFoldersWithTextPairsCountByOwner(owner: string) {
try {
const folders = await pool.query(

View File

@@ -1,4 +1,5 @@
import { Pool } from "pg";
import z from "zod";
export const pool = new Pool({
user: "postgres",
@@ -8,3 +9,16 @@ export const pool = new Pool({
connectionTimeoutMillis: 2000,
maxLifetimeSeconds: 60,
});
export const TextPairSchema = z.object({
id: z.number().int().positive(),
text1: z.string().min(1).max(100),
text2: z.string().min(1).max(100),
locale1: z.string().min(2).max(10),
locale2: z.string().min(2).max(10),
owner: z.string().min(1).max(40),
createdAt: z.date().default(() => new Date()),
updatedAt: z.date().default(() => new Date()),
});
export const