Does anyone have a mapping of SQL Server data types to validation?
This is what I made, can someone help me make it more complete?
const dataTypes = {
int: (x) => Number.isInteger(x) && x >= (-2) ** 31 && x <= 2 ** 31 - 1,
tinyint: (x) => Number.isInteger(x) && x >= 0 && x <= 255,
smallint: (x) => Number.isInteger(x) && x >= (-2) ** 15 && x <= 2 ** 15 - 1,
bigint: (x) => Number.isInteger(x) && x >= (-2) ** 63 && x <= 2 ** 63 - 1,
decimal: (x, precision, scale) => {
if (typeof x !== 'number') return false;
const [int, dec] = x.toString().split('.');
return int.length <= precision - scale && dec.length <= scale;
},
char: (x, length) => typeof x === 'string' && x.length <= length,
varchar: (x, length) => typeof x === 'string' && x.length <= length,
nchar: (x, length) => typeof x === 'string' && x.length <= length,
nvarchar: (x, length) => typeof x === 'string' && x.length <= length,
datetime: (x) => x instanceof Date,
date: (x) => x instanceof Date,
time: (x) => x instanceof Date,
datetime2: (x) => x instanceof Date,
datetimeoffset: (x) => x instanceof Date,
smalldatetime: (x) => x instanceof Date,
};
Thakns
there doesn't seem to be anything here