feat: add getSongInfos to db managing.ts

This commit is contained in:
robin committed 2026-07-28 14:48:28 +02:00
1 parent 011f1b6e0b
commit d6fb6ec16d
1 file changed
+26 -1
+26 -1
View File
@@ -1,5 +1,4 @@
import Database from "better-sqlite3";
import { Noto_Sans_Tamil_Supplement } from "next/font/google";
import path from "path";
const dbPath = path.join(process.cwd(), "songs.db");
@@ -69,6 +68,32 @@ export async function getSong(songbookId: number, songId: string) {
}
}
export async function getSongInfos(songId: string) {
try {
const songRecords = db.prepare(`
SELECT
ss.songbook_id,
sb.name AS songbook_name,
ss.song_number,
s.title
FROM songbook_songs ss
JOIN songbooks sb ON ss.songbook_id = sb.id
JOIN songs s ON ss.song_id = s.id
WHERE s.id = ?
`).all(songId) as {
songbook_id: number;
songbook_name: string;
song_number: string;
title: string;
}[] | undefined
return songRecords || null;
} catch (error) {
console.error("Fehler in getSong:", error);
return null;
}
}
export async function addSongToSongbook(title:string, songbookId:number, number:string) {
try {
const runTransaction = db.transaction(() => {