library/lib/books.ts

36 lines
996 B
TypeScript

import sqlite3 from "sqlite3";
const DATABASE_PATH = "catalogue.db";
async function getBook(id: number) {
const database = new sqlite3.Database(DATABASE_PATH, sqlite3.OPEN_READONLY);
const sql =
"SELECT isbn, lccn, title, subtitle, authors, edition, publisher, publish_year, publish_month, publish_location, pages, pagination, weight, last_updated, deleted FROM books WHERE id = ? ";
await database.get(sql, [id], (err: Error | null, book: DetailedBook) => {
if (err) {
return console.error(err.message);
}
console.log(book);
});
database.close();
}
export interface DetailedBook {
isbn: string | null;
lccn: string | null;
title: string;
authors: string | null;
edition: string | null;
publisher: string | null;
publish_year: string | null;
publish_month: string | null;
publish_location: string | null;
pages: string | null;
pagination: string | null;
weight: string | null;
last_updated: Date | null;
deleted: boolean | null;
}