Get details for one book #14
Loading…
Reference in New Issue
No description provided.
Delete Branch "j285he-one-book"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #3
@ -0,0 +20,4 @@
}
});
});
// .then((newBook) => {
Some questions...
Would it be better to have the database.close in the
finally
statement? Also, would it be benificial to have thecatch
statement so that error messages are console.logged?However, adding the catch statement changes the type of book to be
Promise<unknown>
. I believe this is because the catch function doesn't return anything, the promise returned by then gets resolved with an undefined value..Good questions!
This is a good question! It seems like if we put the
database.close
in thefinally
block, then the database is only closed after the promise has been fulfilled or rejected, whereas if thedatabase.close
is not in thefinally
block, it seems like the database closes earlier but everything still works? Maybe @a3thakra or @n3parikh can give some insight...This probably isn't necessary, as any errors should be logged automatically.
I also found this article about error handling that has a short section on "Returning errors in promises" - it seems like we can just
reject(err)
, and then when we callgetBook
from the frontend or wherever we can consider catching errors there.@ -0,0 +6,4 @@
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 = ? ";
Do we want to be able to query for deleted books, given the deleted book's id? Or should we perhaps restrict ourselves to only books with
deleted = 0
?Good idea, querying a deleted book now throws an error
@ -25,0 +49,4 @@
isbn: string | null;
lccn: string | null;
title: string | null;
authors: string | null;
Are the authors going to be stored in a list of strings or are we going to have one string with the list of all author names separated by a comma?
The database stores the authors field as one string, with names separated by commas.
@ -5,0 +6,4 @@
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 = ? AND deleted = 0";
Just a small nitpick, we probably don't need to
SELECT deleted FROM books
since we know we're only querying for books withdeleted = 0
.👍