Add basic getAllBooks API
This commit is contained in:
parent
12d2ce1a0d
commit
3f3eee108c
|
@ -0,0 +1,26 @@
|
|||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import sqlite3 from "sqlite3";
|
||||
|
||||
const DATABASE_PATH = "catalogue.db";
|
||||
|
||||
export default async function getAllBooks(
|
||||
request: NextApiRequest,
|
||||
response: NextApiResponse
|
||||
) {
|
||||
const database = new sqlite3.Database(DATABASE_PATH, sqlite3.OPEN_READONLY);
|
||||
|
||||
database.all(
|
||||
"SELECT title, authors, isbn FROM books",
|
||||
(error, rows: SimpleBook[]) => {
|
||||
response.status(200).json(rows);
|
||||
}
|
||||
);
|
||||
|
||||
database.close();
|
||||
}
|
||||
|
||||
export interface SimpleBook {
|
||||
authors: string;
|
||||
isbn: string;
|
||||
title: string;
|
||||
}
|
Loading…
Reference in New Issue