<commit_before>const pgp = require('pg-promise')()
const dbName = 'LitPit'
const connectionString = `postgres://${process.env.USER}@localhost:5432/${dbName}`
const db = pgp(connectionString)

const getAllResources = 'SELECT * FROM resources LIMIT 10 OFFSET $1'

const addResource = 'INSERT INTO resources (id, title, description, image_link, url) VALUES (DEFAULT, $1, $2, $3, $4) RETURNING id'

const addAuthor = 'INSERT INTO authors (id, name) VALUES (DEFAULT, $1) ON CONFLICT DO NOTHING; INSERT INTO resource_authors (author_id, resource_id) SELECT authors.id, resources.id FROM authors JOIN resources ON resources.id = $2 WHERE name = $1'

const addCategory = 'INSERT INTO categories (id, name) VALUES (DEFAULT, $1) ON CONFLICT DO NOTHING; INSERT INTO resource_categories (category_id, resource_id) SELECT categories.id, resources.id FROM categories JOIN resources ON resources.id = $2 WHERE name = $1 ON CONFLICT DO NOTHING'


const Resources = {
  all: (offset) => {
    return db.any( getAllResources, [offset] )
  },
  createAuthor: (author, resource_id) => {
    return db.any( addAuthor, [author, resource_id])
  },
  createCategory: (category, resource_id) => {
    return db.any( addCategory, [category, resource_id] )
  },
  createResource: (title, description, image_link, url, authors, categories) => {<commit_msg>Test addBook functionality and modify addBook form<commit_after>const pgp = require('pg-promise')()
const dbName = 'LitPit'
const connectionString = `postgres://${process.env.USER}@localhost:5432/${dbName}`
const db = pgp(connectionString)

const getAllResources = 'SELECT * FROM resources LIMIT 10 OFFSET $1'

const addResource = 'INSERT INTO resources (id, title, description, image_link, url) VALUES (DEFAULT, $1, $2, $3, $4) RETURNING id'

const addAuthor = 'INSERT INTO authors (id, name) VALUES (DEFAULT, $1) ON CONFLICT DO NOTHING; INSERT INTO resource_authors (author_id, resource_id) SELECT authors.id, resources.id FROM authors JOIN resources ON resources.id = $2 WHERE name = $1'

const addCategory = 'INSERT INTO categories (id, name) VALUES (DEFAULT, $1) ON CONFLICT DO NOTHING; INSERT INTO resource_categories (category_id, resource_id) SELECT categories.id, resources.id FROM categories JOIN resources ON resources.id = $2 WHERE name = $1 ON CONFLICT DO NOTHING'


const Resources = {
  all: (offset) => {
    return db.any( getAllResources, [offset] )
  },
  createAuthor: (author, resource_id) => {
    return db.one( addAuthor, [author, resource_id])
  },
  createCategory: (category, resource_id) => {
    return db.any( addCategory, [category, resource_id] )
  },
  createResource: (title, description, image_link, url) => {
{'fraction_non_alphanumeric': 0.11976047904191617, 'fraction_numerical': 0.012724550898203593, 'mean_word_length': 5.230769230769231, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1596273', 'n_tokens_mistral': 851, 'n_tokens_neox': 810, 'n_words': 280}