save current changes

This commit is contained in:
2025-08-17 17:47:54 +02:00
parent 60a5272054
commit dc4e57db2c
15 changed files with 944 additions and 68 deletions

59
src/lib/db/video.ts Normal file
View File

@ -0,0 +1,59 @@
import { query } from '../mysql';
export interface Video {
id: number;
created_at: Date;
modified_at: Date;
genre: string;
sub_genre: string;
scene: string;
action: string;
camera: string;
image_prompt: string;
video_prompt: string;
image_path: string;
video_path: string;
}
export class VideoModel {
static async create(video: Omit<Video, 'id' | 'created_at' | 'modified_at'>): Promise<number> {
const sql = 'INSERT INTO video (genre, sub_genre, scene, action, camera, image_prompt, video_prompt, image_path, video_path) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)';
const params = [video.genre, video.sub_genre, video.scene, video.action, video.camera, video.image_prompt, video.video_prompt, video.image_path, video.video_path];
const result: any = await query(sql, params);
return result.insertId;
}
static async getById(id: number): Promise<Video | null> {
const sql = 'SELECT * FROM video WHERE id = ?';
const params = [id];
const rows: any = await query(sql, params);
return rows.length > 0 ? rows[0] as Video : null;
}
static async getAll(): Promise<Video[]> {
const sql = 'SELECT * FROM video';
const rows: any = await query(sql);
return rows as Video[];
}
static async update(id: number, video: Partial<Omit<Video, 'id' | 'created_at' | 'modified_at'>>): Promise<boolean> {
const fields = Object.keys(video);
const values = Object.values(video);
if (fields.length === 0) {
return false;
}
const sql = `UPDATE video SET ${fields.map(field => `${field} = ?`).join(', ')} WHERE id = ?`;
const params = [...values, id];
const result: any = await query(sql, params);
return result.affectedRows > 0;
}
static async delete(id: number): Promise<boolean> {
const sql = 'DELETE FROM video WHERE id = ?';
const params = [id];
const result: any = await query(sql, params);
return result.affectedRows > 0;
}
}