Add query for one book

This commit is contained in:
Jared He 2022-02-14 00:44:36 -05:00
parent 91ef014ee5
commit bd9f8c9a60
2 changed files with 36 additions and 1 deletions

35
lib/books.ts Normal file
View File

@ -0,0 +1,35 @@
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;
}

View File

@ -3,7 +3,7 @@
/* Basic Options */ /* Basic Options */
"incremental": true, "incremental": true,
"target": "ES6", "target": "ES6",
"module": "esnext", "module": "CommonJS",
"moduleResolution": "node", "moduleResolution": "node",
"lib": ["dom", "dom.iterable", "esnext"], "lib": ["dom", "dom.iterable", "esnext"],
"sourceMap": true, "sourceMap": true,