release: v0.2.1 生产加固 — WAL CRC/约束激活/Hybrid提交顺序/RESTRICT外键/浏览器兼容表/debug模式/onError回调
CI / test (20.x) (push) Successful in 9m58s
CI / test (18.x) (push) Successful in 10m0s
CI / test (22.x) (push) Successful in 10m0s
CI / test (24.x) (push) Successful in 9m56s

This commit is contained in:
thzxx
2026-07-27 20:47:30 +08:00
parent 620cd11521
commit e6efa39d48
18 changed files with 357 additions and 27 deletions
+20 -2
View File
@@ -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':