mirror of
https://github.com/austinried/subtracks.git
synced 2026-02-11 15:22:43 +01:00
moooore styling
started albums these commits are messy
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Artist } from '../models/music';
|
||||
import { Album, Artist } from '../models/music';
|
||||
import { DbStorage } from './db';
|
||||
|
||||
export class MusicDb extends DbStorage {
|
||||
@@ -10,6 +10,14 @@ export class MusicDb extends DbStorage {
|
||||
await this.initDb(tx => {
|
||||
tx.executeSql(`
|
||||
CREATE TABLE artists (
|
||||
id TEXT PRIMARY KEY NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
starred INTEGER NOT NULL,
|
||||
coverArt TEXT
|
||||
);
|
||||
`);
|
||||
tx.executeSql(`
|
||||
CREATE TABLE albums (
|
||||
id TEXT PRIMARY KEY NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
starred INTEGER NOT NULL
|
||||
@@ -24,6 +32,7 @@ export class MusicDb extends DbStorage {
|
||||
`))[0].rows.raw().map(x => ({
|
||||
id: x.id,
|
||||
name: x.name,
|
||||
coverArt: x.coverArt || undefined,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -34,7 +43,30 @@ export class MusicDb extends DbStorage {
|
||||
`);
|
||||
for (const a of artists) {
|
||||
tx.executeSql(`
|
||||
INSERT INTO artists (id, name, starred)
|
||||
INSERT INTO artists (id, name, starred, coverArt)
|
||||
VALUES (?, ?, ?, ?);
|
||||
`, [a.id, a.name, false, a.coverArt || null]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async getAlbums(): Promise<Album[]> {
|
||||
return (await this.executeSql(`
|
||||
SELECT * FROM albums;
|
||||
`))[0].rows.raw().map(x => ({
|
||||
id: x.id,
|
||||
name: x.name,
|
||||
}));
|
||||
}
|
||||
|
||||
async updateAlbums(albums: Album[]): Promise<void> {
|
||||
await this.transaction((tx) => {
|
||||
tx.executeSql(`
|
||||
DELETE FROM albums
|
||||
`);
|
||||
for (const a of albums) {
|
||||
tx.executeSql(`
|
||||
INSERT INTO albums (id, name, starred)
|
||||
VALUES (?, ?, ?);
|
||||
`, [a.id, a.name, false]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user