moooore styling

started albums
these commits are messy
This commit is contained in:
austinried
2021-06-19 17:19:49 +09:00
parent f19cbabac4
commit c9b096d347
29 changed files with 312 additions and 55 deletions

View File

@@ -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]);
}