<commit_before>const pgp = require('pg-promise')()
const connectionString = 'postgres://localhost:5432/sweethornbillbookstore'
const db = pgp(connectionString)

const getAllBooks = () => db.any( 'SELECT * FROM books' )

const getSingleBook = ( request, response ) => {
  const id = request.params.id
  return db.one('SELECT * FROM books WHERE id = $1', id)
}

const getSingleAuthor = ( request, response ) => {
  const author = request.params.author.toLowerCase()
    return db.any('SELECT * FROM books WHERE LOWER(author) = $1', author)
}

const getSingleGenre = ( request, response ) => {
  const genre = request.params.genre
  return db.one('SELECT * FROM books WHERE genre = $1', genre)
}


const updateBook = data => {
  return db.oneOrNone(`
    UPDATE books
    SET title=$2,
        author=$3,
        genre=$4,
        description=$5
    WHERE id = $1`, [data.id, data.title, data.author, data.genre, data.description] )
}

const addBookPage = ( request, response ) => {
  return db.any('SELECT * FROM books')
}

const createBook = ( request, response ) => {
  const { title, author, genre, description, img_url } = request.body
  return db.any(`
    INSERT INTO books( title, author, genre, description, img_url)
    VALUES( $1, $2, $3, $4, $5 )
    RETURNING *`, [title, author, genre, description, img_url])
}

module.exports = {
  getAllBooks,
  getSingleBook,
  getSingleAuthor,
  getSingleGenre,
  updateBook,<commit_msg>finishes add/create book functionality  - adds styling to addBook page<commit_after>const pgp = require('pg-promise')()
const connectionString = 'postgres://localhost:5432/sweethornbillbookstore'
const db = pgp(connectionString)

const getAllBooks = () => db.any( 'SELECT * FROM books' )

const getSingleBook = ( request, response ) => {
  const id = request.params.id
  return db.one('SELECT * FROM books WHERE id = $1', id)
}

const getSingleAuthor = ( request, response ) => {
  const author = request.params.author.toLowerCase()
    return db.any('SELECT * FROM books WHERE LOWER(author) = $1', author)
}

const getSingleGenre = ( request, response ) => {
  const genre = request.params.genre
  return db.one('SELECT * FROM books WHERE genre = $1', genre)
}

const updateBook = data => {
  return db.oneOrNone(`
    UPDATE books
    SET title=$2,
        author=$3,
        genre=$4,
        description=$5
    WHERE id = $1`, [data.id, data.title, data.author, data.genre, data.description] )
}

const addBookPage = ( request, response ) => {
  return db.any('SELECT * FROM books')
}

const createBook = ( request, response ) => {
  const { title, author, genre, description, img_url } = request.body
  return db.any(`
    INSERT INTO books( title, author, genre, description, img_url)
    VALUES( $1, $2, $3, $4, $5 )
    RETURNING *`, [title, author, genre, description, img_url])
}

module.exports = {
  getAllBooks,
  getSingleBook,
  getSingleAuthor,
  getSingleGenre,
  updateBook,
{'fraction_non_alphanumeric': 0.13797814207650272, 'fraction_numerical': 0.011612021857923498, 'mean_word_length': 3.770358306188925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2695757', 'n_tokens_mistral': 957, 'n_tokens_neox': 936, 'n_words': 261}