31 lines
655 B
TypeScript
31 lines
655 B
TypeScript
import sqlite3 from "sqlite3";
|
|
|
|
const DATABASE_PATH = "catalogue.db";
|
|
|
|
export async function getAllBooks() {
|
|
const database = new sqlite3.Database(DATABASE_PATH, sqlite3.OPEN_READONLY);
|
|
|
|
const books = new Promise<SimpleBook[]>((resolve, reject) => {
|
|
database.all(
|
|
"SELECT id, title, authors, isbn FROM books WHERE deleted = 0",
|
|
(error: Error | null, rows: SimpleBook[]) => {
|
|
if (error) {
|
|
reject(error);
|
|
}
|
|
resolve(rows);
|
|
}
|
|
);
|
|
});
|
|
|
|
database.close();
|
|
|
|
return books;
|
|
}
|
|
|
|
export interface SimpleBook {
|
|
id: number;
|
|
title: string | null;
|
|
authors: string | null;
|
|
isbn: string | null;
|
|
}
|