Files
profilarr/src/lib/server/db/queries/tmdbSettings.ts
Sam Chau 74b38df686 feat: add entity and release management components
- Created EntityTable component for displaying test entities with expandable rows for releases.
- Implemented ReleaseTable component to manage and display test releases with actions for editing and deleting.
- Added ReleaseModal component for creating and editing releases
- Introduced types for TestEntity, TestRelease, and related evaluations
- Enhanced general settings page to include TMDB API configuration with connection testing functionality.
- Added TMDBSettings component for managing TMDB API access token with reset and test connection features.
2026-01-14 23:50:20 +10:30

71 lines
1.3 KiB
TypeScript

import { db } from '../db.ts';
/**
* Types for tmdb_settings table
*/
export interface TMDBSettings {
id: number;
api_key: string;
created_at: string;
updated_at: string;
}
export interface UpdateTMDBSettingsInput {
apiKey?: string;
}
/**
* All queries for tmdb_settings table
* Singleton pattern - only one settings record exists
*/
export const tmdbSettingsQueries = {
/**
* Get the TMDB settings (singleton)
*/
get(): TMDBSettings | undefined {
return db.queryFirst<TMDBSettings>('SELECT * FROM tmdb_settings WHERE id = 1');
},
/**
* Update TMDB settings
*/
update(input: UpdateTMDBSettingsInput): boolean {
const updates: string[] = [];
const params: (string | number)[] = [];
if (input.apiKey !== undefined) {
updates.push('api_key = ?');
params.push(input.apiKey);
}
if (updates.length === 0) {
return false;
}
// Add updated_at
updates.push('updated_at = CURRENT_TIMESTAMP');
params.push(1); // id is always 1
const affected = db.execute(
`UPDATE tmdb_settings SET ${updates.join(', ')} WHERE id = ?`,
...params
);
return affected > 0;
},
/**
* Reset TMDB settings to defaults
*/
reset(): boolean {
const affected = db.execute(`
UPDATE tmdb_settings SET
api_key = '',
updated_at = CURRENT_TIMESTAMP
WHERE id = 1
`);
return affected > 0;
}
};