Merge main
continuous-integration/drone/pr Build is passing Details
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Jared He 2022-03-16 18:18:56 -04:00
commit f1994b2f5d
2 changed files with 44 additions and 3 deletions

View File

@ -22,10 +22,29 @@ export async function getBook(id: number): Promise<DetailedBook> {
});
database.close();
return book;
}
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 DetailedBook {
isbn: string | null;
lccn: string | null;
@ -42,3 +61,10 @@ export interface DetailedBook {
last_updated: Date | null;
deleted: boolean | null;
}
export interface SimpleBook {
id: number;
title: string | null;
authors: string | null;
isbn: string | null;
}

View File

@ -1,19 +1,34 @@
import React from "react";
import { getBook, DetailedBook } from "../lib/books";
import { getBook, getAllBooks, DetailedBook, SimpleBook } from "../lib/books";
export default function Home(props: Props) {
return <p>{props.book.title}</p>;
return (
<div>
<ul>
{props.books.map((book, idx) => {
return (
<li key={`${idx}_${book.id}`}>
{book.id}; {book.title}; {book.authors}; {book.isbn}
</li>
);
})}
</ul>
<p>{props.book.title}</p>
</div>
);
}
interface Props {
book: DetailedBook;
books: SimpleBook[];
}
export async function getServerSideProps() {
return {
props: {
book: await getBook(44),
books: await getAllBooks(),
},
};
}