Refactor BookRepo methods and improve error handling

- Add JSDoc comments for better maintainability and code clarity in `BookRepo` methods.
- Streamline query definitions using variables to improve readability.
- Consolidate error handling logic across all methods.
- Ensure multilingual support in error messages for consistent user feedback.
- Remove redundant error branches and simplify unknown error processing.
This commit is contained in:
natreex
2026-01-12 09:57:37 -05:00
parent 9ad2ee9692
commit d9bf089e32
12 changed files with 3202 additions and 1252 deletions

View File

@@ -1,6 +1,5 @@
import {Database, RunResult, SQLiteValue} from "node-sqlite3-wasm";
import { Database, RunResult, SQLiteValue } from "node-sqlite3-wasm";
import System from "@/electron/database/System";
import {ChapterBookResult, EritBooksTable} from "@/electron/database/repositories/book.repository";
export interface BookAIGuideLineTable extends Record<string, SQLiteValue> {
user_id: string;
@@ -72,35 +71,111 @@ export interface GuideLineAIQuery extends Record<string, SQLiteValue> {
}
export default class GuidelineRepo {
/**
* Fetches the guideline for a specific book.
* @param userId - The user identifier
* @param bookId - The book identifier
* @param lang - The language for error messages ('fr' or 'en')
* @returns An array of guideline query results
* @throws Error if the guideline cannot be retrieved
*/
public static fetchGuideLine(userId: string, bookId: string, lang: 'fr' | 'en'): GuideLineQuery[] {
let result: GuideLineQuery[];
let guidelines: GuideLineQuery[];
try {
const db: Database = System.getDb();
result = db.all('SELECT * FROM book_guide_line WHERE book_id=? AND user_id=?', [bookId, userId]) as GuideLineQuery[];
} catch (e: unknown) {
if (e instanceof Error) {
console.error(`DB Error: ${e.message}`);
const query: string = 'SELECT * FROM book_guide_line WHERE book_id=? AND user_id=?';
const params: SQLiteValue[] = [bookId, userId];
guidelines = db.all(query, params) as GuideLineQuery[];
} catch (error: unknown) {
if (error instanceof Error) {
console.error(`DB Error: ${error.message}`);
throw new Error(lang === 'fr' ? `Impossible de récupérer la ligne directrice.` : `Unable to retrieve guideline.`);
} else {
console.error("An unknown error occurred.");
throw new Error(lang === 'fr' ? "Une erreur inconnue s'est produite." : "An unknown error occurred.");
}
}
return result;
return guidelines;
}
static updateGuideLine(userId: string, bookId: string, encryptedTone: string, encryptedAtmosphere: string, encryptedWritingStyle: string, encryptedThemes: string, encryptedSymbolism: string, encryptedMotifs: string, encryptedNarrativeVoice: string, encryptedPacing: string, encryptedKeyMessages: string, encryptedIntendedAudience: string, lang: 'fr' | 'en'): boolean {
/**
* Updates or inserts a guideline for a specific book.
* If the guideline exists, it updates it; otherwise, it inserts a new one.
* @param userId - The user identifier
* @param bookId - The book identifier
* @param encryptedTone - The encrypted tone value
* @param encryptedAtmosphere - The encrypted atmosphere value
* @param encryptedWritingStyle - The encrypted writing style value
* @param encryptedThemes - The encrypted themes value
* @param encryptedSymbolism - The encrypted symbolism value
* @param encryptedMotifs - The encrypted motifs value
* @param encryptedNarrativeVoice - The encrypted narrative voice value
* @param encryptedPacing - The encrypted pacing value
* @param encryptedKeyMessages - The encrypted key messages value
* @param encryptedIntendedAudience - The encrypted intended audience value
* @param lang - The language for error messages ('fr' or 'en')
* @returns True if the operation was successful
* @throws Error if the guideline cannot be updated or inserted
*/
static updateGuideLine(
userId: string,
bookId: string,
encryptedTone: string,
encryptedAtmosphere: string,
encryptedWritingStyle: string,
encryptedThemes: string,
encryptedSymbolism: string,
encryptedMotifs: string,
encryptedNarrativeVoice: string,
encryptedPacing: string,
encryptedKeyMessages: string,
encryptedIntendedAudience: string,
lang: 'fr' | 'en'
): boolean {
try {
const db: Database = System.getDb();
const result: RunResult = db.run('UPDATE book_guide_line SET tone=?, atmosphere=?, writing_style=?, themes=?, symbolism=?, motifs=?, narrative_voice=?, pacing=?, key_messages=?, last_update=? WHERE user_id=? AND book_id=?', [encryptedTone, encryptedAtmosphere, encryptedWritingStyle, encryptedThemes, encryptedSymbolism, encryptedMotifs, encryptedNarrativeVoice, encryptedPacing, encryptedKeyMessages, System.timeStampInSeconds(), userId, bookId]);
if (result.changes > 0) {
const updateQuery: string = 'UPDATE book_guide_line SET tone=?, atmosphere=?, writing_style=?, themes=?, symbolism=?, motifs=?, narrative_voice=?, pacing=?, key_messages=?, last_update=? WHERE user_id=? AND book_id=?';
const updateParams: SQLiteValue[] = [
encryptedTone,
encryptedAtmosphere,
encryptedWritingStyle,
encryptedThemes,
encryptedSymbolism,
encryptedMotifs,
encryptedNarrativeVoice,
encryptedPacing,
encryptedKeyMessages,
System.timeStampInSeconds(),
userId,
bookId
];
const updateResult: RunResult = db.run(updateQuery, updateParams);
if (updateResult.changes > 0) {
return true;
} else {
const insert:RunResult = db.run('INSERT INTO book_guide_line (user_id, book_id, tone, atmosphere, writing_style, themes, symbolism, motifs, narrative_voice, pacing, intended_audience, key_messages, last_update) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)', [userId, bookId, encryptedTone, encryptedAtmosphere, encryptedWritingStyle, encryptedThemes, encryptedSymbolism, encryptedMotifs, encryptedNarrativeVoice, encryptedPacing, encryptedIntendedAudience, encryptedKeyMessages, System.timeStampInSeconds()]);
return insert.changes > 0;
const insertQuery: string = 'INSERT INTO book_guide_line (user_id, book_id, tone, atmosphere, writing_style, themes, symbolism, motifs, narrative_voice, pacing, intended_audience, key_messages, last_update) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)';
const insertParams: SQLiteValue[] = [
userId,
bookId,
encryptedTone,
encryptedAtmosphere,
encryptedWritingStyle,
encryptedThemes,
encryptedSymbolism,
encryptedMotifs,
encryptedNarrativeVoice,
encryptedPacing,
encryptedIntendedAudience,
encryptedKeyMessages,
System.timeStampInSeconds()
];
const insertResult: RunResult = db.run(insertQuery, insertParams);
return insertResult.changes > 0;
}
} catch (e: unknown) {
if (e instanceof Error) {
console.error(`DB Error: ${e.message}`);
} catch (error: unknown) {
if (error instanceof Error) {
console.error(`DB Error: ${error.message}`);
throw new Error(lang === 'fr' ? `Impossible de mettre à jour la ligne directrice.` : `Unable to update guideline.`);
} else {
console.error("An unknown error occurred.");
@@ -108,19 +183,76 @@ export default class GuidelineRepo {
}
}
}
static insertAIGuideLine(userId: string, bookId: string, narrativeType: number, dialogueType: number, encryptedPlotSummary: string, encryptedToneAtmosphere: string, verbTense: number, language: number, encryptedThemes: string, lang: 'fr' | 'en'): boolean {
/**
* Inserts or updates an AI guideline for a specific book.
* If the AI guideline exists, it updates it; otherwise, it inserts a new one.
* @param userId - The user identifier
* @param bookId - The book identifier
* @param narrativeType - The narrative type identifier
* @param dialogueType - The dialogue type identifier
* @param encryptedPlotSummary - The encrypted plot summary
* @param encryptedToneAtmosphere - The encrypted tone and atmosphere value
* @param verbTense - The verb tense identifier
* @param language - The language identifier
* @param encryptedThemes - The encrypted themes value
* @param lang - The language for error messages ('fr' or 'en')
* @returns True if the operation was successful
* @throws Error if the AI guideline cannot be inserted or updated
*/
static insertAIGuideLine(
userId: string,
bookId: string,
narrativeType: number,
dialogueType: number,
encryptedPlotSummary: string,
encryptedToneAtmosphere: string,
verbTense: number,
language: number,
encryptedThemes: string,
lang: 'fr' | 'en'
): boolean {
try {
const db: Database = System.getDb();
let result: RunResult = db.run('UPDATE book_ai_guide_line SET narrative_type=?, dialogue_type=?, global_resume=?, atmosphere=?, verbe_tense=?, langue=?, themes=?, last_update=? WHERE user_id=? AND book_id=?', [narrativeType ? narrativeType : null, dialogueType ? dialogueType : null, encryptedPlotSummary, encryptedToneAtmosphere, verbTense ? verbTense : null, language ? language : null, encryptedThemes, System.timeStampInSeconds(), userId, bookId]);
if (result.changes > 0) {
const updateQuery: string = 'UPDATE book_ai_guide_line SET narrative_type=?, dialogue_type=?, global_resume=?, atmosphere=?, verbe_tense=?, langue=?, themes=?, last_update=? WHERE user_id=? AND book_id=?';
const updateParams: SQLiteValue[] = [
narrativeType ? narrativeType : null,
dialogueType ? dialogueType : null,
encryptedPlotSummary,
encryptedToneAtmosphere,
verbTense ? verbTense : null,
language ? language : null,
encryptedThemes,
System.timeStampInSeconds(),
userId,
bookId
];
const updateResult: RunResult = db.run(updateQuery, updateParams);
if (updateResult.changes > 0) {
return true;
} else {
result = db.run('INSERT INTO book_ai_guide_line (user_id, book_id, global_resume, themes, verbe_tense, narrative_type, langue, dialogue_type, tone, atmosphere, current_resume, last_update) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)', [userId, bookId, encryptedPlotSummary, encryptedThemes, verbTense ? verbTense : null, narrativeType ? narrativeType : null, language ? language : null, dialogueType ? dialogueType : null, encryptedToneAtmosphere, encryptedToneAtmosphere, encryptedPlotSummary, System.timeStampInSeconds()]);
return result.changes > 0;
const insertQuery: string = 'INSERT INTO book_ai_guide_line (user_id, book_id, global_resume, themes, verbe_tense, narrative_type, langue, dialogue_type, tone, atmosphere, current_resume, last_update) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)';
const insertParams: SQLiteValue[] = [
userId,
bookId,
encryptedPlotSummary,
encryptedThemes,
verbTense ? verbTense : null,
narrativeType ? narrativeType : null,
language ? language : null,
dialogueType ? dialogueType : null,
encryptedToneAtmosphere,
encryptedToneAtmosphere,
encryptedPlotSummary,
System.timeStampInSeconds()
];
const insertResult: RunResult = db.run(insertQuery, insertParams);
return insertResult.changes > 0;
}
} catch (e: unknown) {
if (e instanceof Error) {
console.error(`DB Error: ${e.message}`);
} catch (error: unknown) {
if (error instanceof Error) {
console.error(`DB Error: ${error.message}`);
throw new Error(lang === 'fr' ? `Impossible d'insérer la ligne directrice IA.` : `Unable to insert AI guideline.`);
} else {
console.error("An unknown error occurred.");
@@ -128,59 +260,104 @@ export default class GuidelineRepo {
}
}
}
/**
* Fetches the AI guideline for a specific book.
* @param userId - The user identifier
* @param bookId - The book identifier
* @param lang - The language for error messages ('fr' or 'en')
* @returns The AI guideline query result
* @throws Error if the AI guideline cannot be retrieved or is not found
*/
static fetchGuideLineAI(userId: string, bookId: string, lang: 'fr' | 'en'): GuideLineAIQuery {
let result: GuideLineAIQuery | null;
let aiGuideline: GuideLineAIQuery | null;
try {
const db: Database = System.getDb();
result = db.get('SELECT narrative_type, dialogue_type, global_resume, atmosphere, verbe_tense, langue, themes, current_resume FROM book_ai_guide_line WHERE user_id=? AND book_id=?', [userId, bookId]) as GuideLineAIQuery | null;
} catch (e: unknown) {
if (e instanceof Error) {
console.error(`DB Error: ${e.message}`);
const query: string = 'SELECT narrative_type, dialogue_type, global_resume, atmosphere, verbe_tense, langue, themes, current_resume FROM book_ai_guide_line WHERE user_id=? AND book_id=?';
const params: SQLiteValue[] = [userId, bookId];
aiGuideline = db.get(query, params) as GuideLineAIQuery | null;
} catch (error: unknown) {
if (error instanceof Error) {
console.error(`DB Error: ${error.message}`);
throw new Error(lang === 'fr' ? `Impossible de récupérer la ligne directrice IA.` : `Unable to retrieve AI guideline.`);
} else {
console.error("An unknown error occurred.");
throw new Error(lang === 'fr' ? "Une erreur inconnue s'est produite." : "An unknown error occurred.");
}
}
if (!result) {
if (!aiGuideline) {
throw new Error(lang === 'fr' ? `Ligne directrice IA non trouvée.` : `AI guideline not found.`);
}
return result;
return aiGuideline;
}
/**
* Fetches the book AI guideline table data for a specific book.
* @param userId - The user identifier
* @param bookId - The book identifier
* @param lang - The language for error messages ('fr' or 'en')
* @returns A promise resolving to an array of book AI guideline table entries
* @throws Error if the AI guideline cannot be retrieved
*/
static async fetchBookAIGuideLine(userId: string, bookId: string, lang: 'fr' | 'en'): Promise<BookAIGuideLineTable[]> {
try {
const db: Database = System.getDb();
return db.all('SELECT user_id, book_id, global_resume, themes, verbe_tense, narrative_type, langue, dialogue_type, tone, atmosphere, current_resume, last_update FROM book_ai_guide_line WHERE user_id=? AND book_id=?', [userId, bookId]) as BookAIGuideLineTable[];
} catch (e: unknown) {
if (e instanceof Error) {
console.error(`DB Error: ${e.message}`);
const query: string = 'SELECT user_id, book_id, global_resume, themes, verbe_tense, narrative_type, langue, dialogue_type, tone, atmosphere, current_resume, last_update FROM book_ai_guide_line WHERE user_id=? AND book_id=?';
const params: SQLiteValue[] = [userId, bookId];
const aiGuidelines: BookAIGuideLineTable[] = db.all(query, params) as BookAIGuideLineTable[];
return aiGuidelines;
} catch (error: unknown) {
if (error instanceof Error) {
console.error(`DB Error: ${error.message}`);
throw new Error(lang === 'fr' ? `Impossible de récupérer la ligne directrice IA.` : `Unable to retrieve AI guideline.`);
} else {
throw new Error(lang === 'fr' ? "Une erreur inconnue s'est produite." : "An unknown error occurred.");
}
}
}
/**
* Fetches the book guideline table data for a specific book.
* @param userId - The user identifier
* @param bookId - The book identifier
* @param lang - The language for error messages ('fr' or 'en')
* @returns A promise resolving to an array of book guideline table entries
* @throws Error if the guideline cannot be retrieved
*/
static async fetchBookGuideLineTable(userId: string, bookId: string, lang: 'fr' | 'en'): Promise<BookGuideLineTable[]> {
try {
const db: Database = System.getDb();
return db.all('SELECT user_id, book_id, tone, atmosphere, writing_style, themes, symbolism, motifs, narrative_voice, pacing, intended_audience, key_messages, last_update FROM book_guide_line WHERE user_id=? AND book_id=?', [userId, bookId]) as BookGuideLineTable[];
} catch (e: unknown) {
if (e instanceof Error) {
console.error(`DB Error: ${e.message}`);
const query: string = 'SELECT user_id, book_id, tone, atmosphere, writing_style, themes, symbolism, motifs, narrative_voice, pacing, intended_audience, key_messages, last_update FROM book_guide_line WHERE user_id=? AND book_id=?';
const params: SQLiteValue[] = [userId, bookId];
const guidelines: BookGuideLineTable[] = db.all(query, params) as BookGuideLineTable[];
return guidelines;
} catch (error: unknown) {
if (error instanceof Error) {
console.error(`DB Error: ${error.message}`);
throw new Error(lang === 'fr' ? `Impossible de récupérer la ligne directrice.` : `Unable to retrieve guideline.`);
} else {
throw new Error(lang === 'fr' ? "Une erreur inconnue s'est produite." : "An unknown error occurred.");
}
}
}
/**
* Fetches all synced guidelines for a specific user.
* @param userId - The user identifier
* @param lang - The language for error messages ('fr' or 'en')
* @returns An array of synced guideline results containing book_id and last_update
* @throws Error if the synced guidelines cannot be retrieved
*/
static fetchSyncedGuideLine(userId: string, lang: 'fr' | 'en'): SyncedGuideLineResult[] {
try {
const db: Database = System.getDb();
return db.all('SELECT book_id, last_update FROM book_guide_line WHERE user_id = ?', [userId]) as SyncedGuideLineResult[];
} catch (e: unknown) {
if (e instanceof Error) {
console.error(`DB Error: ${e.message}`);
const query: string = 'SELECT book_id, last_update FROM book_guide_line WHERE user_id = ?';
const params: SQLiteValue[] = [userId];
const syncedGuidelines: SyncedGuideLineResult[] = db.all(query, params) as SyncedGuideLineResult[];
return syncedGuidelines;
} catch (error: unknown) {
if (error instanceof Error) {
console.error(`DB Error: ${error.message}`);
throw new Error(lang === 'fr' ? `Impossible de récupérer les lignes directrices synchronisées.` : `Unable to retrieve synced guidelines.`);
} else {
console.error("An unknown error occurred.");
@@ -188,14 +365,24 @@ export default class GuidelineRepo {
}
}
}
/**
* Fetches all synced AI guidelines for a specific user.
* @param userId - The user identifier
* @param lang - The language for error messages ('fr' or 'en')
* @returns An array of synced AI guideline results containing book_id and last_update
* @throws Error if the synced AI guidelines cannot be retrieved
*/
static fetchSyncedAIGuideLine(userId: string, lang: 'fr' | 'en'): SyncedAIGuideLineResult[] {
try {
const db: Database = System.getDb();
return db.all('SELECT book_id, last_update FROM book_ai_guide_line WHERE user_id = ?', [userId]) as SyncedAIGuideLineResult[];
} catch (e: unknown) {
if (e instanceof Error) {
console.error(`DB Error: ${e.message}`);
const query: string = 'SELECT book_id, last_update FROM book_ai_guide_line WHERE user_id = ?';
const params: SQLiteValue[] = [userId];
const syncedAIGuidelines: SyncedAIGuideLineResult[] = db.all(query, params) as SyncedAIGuideLineResult[];
return syncedAIGuidelines;
} catch (error: unknown) {
if (error instanceof Error) {
console.error(`DB Error: ${error.message}`);
throw new Error(lang === 'fr' ? `Impossible de récupérer les lignes directrices IA synchronisées.` : `Unable to retrieve synced AI guidelines.`);
} else {
console.error("An unknown error occurred.");
@@ -203,40 +390,133 @@ export default class GuidelineRepo {
}
}
}
static insertSyncAIGuideLine(userId: string, bookId: string, globalResume: string | null, themes: string | null, verbeTense: number | null, narrativeType: number | null, langue: number | null, dialogueType: number | null, tone: string | null, atmosphere: string | null, currentResume: string | null, lastUpdate: number, lang: 'fr' | 'en'): boolean {
/**
* Inserts a synced AI guideline for a specific book.
* @param userId - The user identifier
* @param bookId - The book identifier
* @param globalResume - The global resume value (nullable)
* @param themes - The themes value (nullable)
* @param verbeTense - The verb tense identifier (nullable)
* @param narrativeType - The narrative type identifier (nullable)
* @param langue - The language identifier (nullable)
* @param dialogueType - The dialogue type identifier (nullable)
* @param tone - The tone value (nullable)
* @param atmosphere - The atmosphere value (nullable)
* @param currentResume - The current resume value (nullable)
* @param lastUpdate - The last update timestamp
* @param lang - The language for error messages ('fr' or 'en')
* @returns True if the insertion was successful
* @throws Error if the AI guideline cannot be inserted
*/
static insertSyncAIGuideLine(
userId: string,
bookId: string,
globalResume: string | null,
themes: string | null,
verbeTense: number | null,
narrativeType: number | null,
langue: number | null,
dialogueType: number | null,
tone: string | null,
atmosphere: string | null,
currentResume: string | null,
lastUpdate: number,
lang: 'fr' | 'en'
): boolean {
try {
const db: Database = System.getDb();
const result: RunResult = db.run(
`INSERT INTO book_ai_guide_line (user_id, book_id, global_resume, themes, verbe_tense, narrative_type, langue, dialogue_type, tone, atmosphere, current_resume, last_update)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
[userId, bookId, globalResume, themes, verbeTense, narrativeType, langue, dialogueType, tone, atmosphere, currentResume, lastUpdate]
);
return result.changes > 0;
} catch (e: unknown) {
if (e instanceof Error) {
console.error(`DB Error: ${e.message}`);
const query: string = `INSERT INTO book_ai_guide_line (user_id, book_id, global_resume, themes, verbe_tense, narrative_type, langue, dialogue_type, tone, atmosphere, current_resume, last_update)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
const params: SQLiteValue[] = [
userId,
bookId,
globalResume,
themes,
verbeTense,
narrativeType,
langue,
dialogueType,
tone,
atmosphere,
currentResume,
lastUpdate
];
const insertResult: RunResult = db.run(query, params);
return insertResult.changes > 0;
} catch (error: unknown) {
if (error instanceof Error) {
console.error(`DB Error: ${error.message}`);
throw new Error(lang === 'fr' ? `Impossible d'insérer la ligne directrice IA.` : `Unable to insert AI guideline.`);
} else {
throw new Error(lang === 'fr' ? "Une erreur inconnue s'est produite." : "An unknown error occurred.");
}
}
}
static insertSyncGuideLine(userId: string, bookId: string, tone: string | null, atmosphere: string | null, writingStyle: string | null, themes: string | null, symbolism: string | null, motifs: string | null, narrativeVoice: string | null, pacing: string | null, intendedAudience: string | null, keyMessages: string | null, lastUpdate: number, lang: 'fr' | 'en'): boolean {
/**
* Inserts a synced guideline for a specific book.
* @param userId - The user identifier
* @param bookId - The book identifier
* @param tone - The tone value (nullable)
* @param atmosphere - The atmosphere value (nullable)
* @param writingStyle - The writing style value (nullable)
* @param themes - The themes value (nullable)
* @param symbolism - The symbolism value (nullable)
* @param motifs - The motifs value (nullable)
* @param narrativeVoice - The narrative voice value (nullable)
* @param pacing - The pacing value (nullable)
* @param intendedAudience - The intended audience value (nullable)
* @param keyMessages - The key messages value (nullable)
* @param lastUpdate - The last update timestamp
* @param lang - The language for error messages ('fr' or 'en')
* @returns True if the insertion was successful
* @throws Error if the guideline cannot be inserted
*/
static insertSyncGuideLine(
userId: string,
bookId: string,
tone: string | null,
atmosphere: string | null,
writingStyle: string | null,
themes: string | null,
symbolism: string | null,
motifs: string | null,
narrativeVoice: string | null,
pacing: string | null,
intendedAudience: string | null,
keyMessages: string | null,
lastUpdate: number,
lang: 'fr' | 'en'
): boolean {
try {
const db: Database = System.getDb();
const result: RunResult = db.run(
`INSERT INTO book_guide_line (user_id, book_id, tone, atmosphere, writing_style, themes, symbolism, motifs, narrative_voice, pacing, intended_audience, key_messages, last_update)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
[userId, bookId, tone, atmosphere, writingStyle, themes, symbolism, motifs, narrativeVoice, pacing, intendedAudience, keyMessages, lastUpdate]
);
return result.changes > 0;
} catch (e: unknown) {
if (e instanceof Error) {
console.error(`DB Error: ${e.message}`);
const query: string = `INSERT INTO book_guide_line (user_id, book_id, tone, atmosphere, writing_style, themes, symbolism, motifs, narrative_voice, pacing, intended_audience, key_messages, last_update)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
const params: SQLiteValue[] = [
userId,
bookId,
tone,
atmosphere,
writingStyle,
themes,
symbolism,
motifs,
narrativeVoice,
pacing,
intendedAudience,
keyMessages,
lastUpdate
];
const insertResult: RunResult = db.run(query, params);
return insertResult.changes > 0;
} catch (error: unknown) {
if (error instanceof Error) {
console.error(`DB Error: ${error.message}`);
throw new Error(lang === 'fr' ? `Impossible d'insérer la ligne directrice.` : `Unable to insert guideline.`);
} else {
throw new Error(lang === 'fr' ? "Une erreur inconnue s'est produite." : "An unknown error occurred.");
}
}
}
}
}