30 lines
776 B
TypeScript
30 lines
776 B
TypeScript
import { Database } from "./database";
|
|
|
|
export type Book = {
|
|
id: number;
|
|
platform: "dmm-books" | "google-play-books";
|
|
readerUrl: string;
|
|
};
|
|
|
|
export function createLibrary(db: Database) {
|
|
return {
|
|
async add(readerUrl: string) {
|
|
const platform = "dmm-books";
|
|
|
|
await db.run(
|
|
`insert into books(reader_url, platform_id) values(?, (select id from platforms where name = ?))`,
|
|
readerUrl,
|
|
platform,
|
|
);
|
|
|
|
console.log(readerUrl);
|
|
},
|
|
async getBooks(): Promise<Array<Book>> {
|
|
const books: Array<Book> = await db.all(
|
|
`select books.id, platforms.name as platform, books.reader_url as readerUrl from books left join platforms on books.platform_id = platforms.id`,
|
|
);
|
|
|
|
return books;
|
|
},
|
|
};
|
|
}
|