feat(profiles): add profile repository

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-17 15:11:23 +02:00
parent 99afc45c29
commit 5693371673
2 changed files with 71 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
import type Database from 'better-sqlite3';
import type { Profile } from '$lib/types';
export function listProfiles(db: Database.Database): Profile[] {
return db
.prepare('SELECT id, name, avatar_emoji FROM profile ORDER BY name')
.all() as Profile[];
}
export function createProfile(
db: Database.Database,
name: string,
avatarEmoji: string | null = null
): Profile {
const trimmed = name.trim();
if (!trimmed) throw new Error('Profile name cannot be empty');
return db
.prepare(
`INSERT INTO profile(name, avatar_emoji) VALUES (?, ?)
RETURNING id, name, avatar_emoji`
)
.get(trimmed, avatarEmoji) as Profile;
}
export function renameProfile(
db: Database.Database,
id: number,
newName: string
): void {
const trimmed = newName.trim();
if (!trimmed) throw new Error('Profile name cannot be empty');
db.prepare('UPDATE profile SET name = ? WHERE id = ?').run(trimmed, id);
}
export function deleteProfile(db: Database.Database, id: number): void {
db.prepare('DELETE FROM profile WHERE id = ?').run(id);
}