1.0.1 • Published 7 years ago

existence-checker v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

existence-checker

makes an express middleware function for checking the existence of the given thing in the database

Usage

const existenceChecker=require('existence-checker')
const express = require('express')
const app = express()
const thingToUpdate = require('yourThingToUpdateController')
const Pool=require('pg').Pool
const config = {
/** db config stuff **/
}
var pool=new Pool(config)
app.put('/api/thingToUpdate/:id',existenceChecker('thingSchema','thingToUpdate','id',pool.query),thingToUpdate.updateThingToUpdate)

existenceChecker(schemaName,tableName,primaryKey,queryExecutor)

makes a middleware function for checking the existence of the given thing in the database

parameters

namedescription
schemaNamethe database schema
tableNamethe thing to check the existence of
primaryKeythe thing's primary key
queryExecutora function that takes a query object and returns the result of the query

returns

a middleware function for checking the existence of the record with primaryKey in tableName