release: v0.2.1 生产加固 — WAL CRC/约束激活/Hybrid提交顺序/RESTRICT外键/浏览器兼容表/debug模式/onError回调
This commit is contained in:
+20
-2
@@ -87,13 +87,13 @@ export function validateRow(schema: TableSchema, row: Record<string, unknown>):
|
||||
return validated;
|
||||
}
|
||||
|
||||
/** 检查字段类型 */
|
||||
/** 检查字段类型(含约束校验) */
|
||||
export function checkFieldType(
|
||||
tableName: string,
|
||||
colName: string,
|
||||
type: FieldType,
|
||||
value: unknown,
|
||||
_colDef?: ColumnDef,
|
||||
colDef?: ColumnDef,
|
||||
): void {
|
||||
const jsType = typeof value;
|
||||
|
||||
@@ -105,6 +105,12 @@ export function checkFieldType(
|
||||
'TYPE_ERROR',
|
||||
);
|
||||
}
|
||||
if (colDef?.maxLength !== undefined && (value as string).length > colDef.maxLength) {
|
||||
throw new DatabaseError(
|
||||
`Column "${colName}" in table "${tableName}" exceeds max length ${colDef.maxLength}`,
|
||||
'VALIDATION_ERROR',
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'number':
|
||||
@@ -114,6 +120,18 @@ export function checkFieldType(
|
||||
'TYPE_ERROR',
|
||||
);
|
||||
}
|
||||
if (colDef?.min !== undefined && (value as number) < colDef.min) {
|
||||
throw new DatabaseError(
|
||||
`Column "${colName}" in table "${tableName}" value ${value} below minimum ${colDef.min}`,
|
||||
'VALIDATION_ERROR',
|
||||
);
|
||||
}
|
||||
if (colDef?.max !== undefined && (value as number) > colDef.max) {
|
||||
throw new DatabaseError(
|
||||
`Column "${colName}" in table "${tableName}" value ${value} above maximum ${colDef.max}`,
|
||||
'VALIDATION_ERROR',
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'boolean':
|
||||
|
||||
Reference in New Issue
Block a user