You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

23 lines
564 B

import { invalid, Validity, Rule } from "https://deno.land/x/validasaur/mod.ts";
/**
*
* @param id
* @return
*/
export function exists(id: string): Rule {
return async function existsRule(value: any): Promise<Validity> {
if (typeof value !== 'string' && typeof value !== 'number') {
return invalid('exists', { value, table, column });
}
const data = await db.findOne({
key: value
})
if (data !== null) {
return invalid('unique', { value, table, column });
}
}
}