This commit is contained in:
dylandefaoite
2025-08-21 14:26:59 +02:00
commit 0a301199a4
24 changed files with 4739 additions and 0 deletions

31
app/src/util/db.ts Normal file
View File

@@ -0,0 +1,31 @@
import { openDB } from 'idb';
export const dbPromise = openDB('spotifyDB', 1, {
upgrade(db) {
if (!db.objectStoreNames.contains('streams')) {
db.createObjectStore('streams', { keyPath: 'id', autoIncrement: true });
}
},
});
export async function addStreams(streamArray: any[]) {
const db = await dbPromise;
const tx = db.transaction('streams', 'readwrite');
const store = tx.objectStore('streams');
// Clear previous data if you want a fresh upload each time
await store.clear();
for (const stream of streamArray) {
await store.add(stream);
}
await tx.done;
}
export async function getAllStreams() {
const db = await dbPromise;
const tx = db.transaction('streams', 'readonly');
const store = tx.objectStore('streams');
return await store.getAll();
}