30 lines
598 B
TypeScript
30 lines
598 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 title, authors, isbn FROM books",
|
|
(error: Error | null, rows: SimpleBook[]) => {
|
|
if (error) {
|
|
reject(error);
|
|
}
|
|
resolve(rows);
|
|
}
|
|
);
|
|
});
|
|
|
|
database.close();
|
|
|
|
return books;
|
|
}
|
|
|
|
export interface SimpleBook {
|
|
authors: string;
|
|
isbn: string;
|
|
title: string;
|
|
}
|