Files
spotify-window/app/src/util/db.ts
dylandefaoite 0a301199a4 init
2025-08-21 14:26:59 +02:00

32 lines
802 B
TypeScript

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();
}