fix: v0.7.3 数据正确性与边界窗口收尾 — INSERT 语句级原子(三引擎+Aria PK 批内重复)/ 索引列 IS NULL 恒空 / delete RESTRICT 破坏索引 / queryStream 子查询静默空结果 / ALTER DROP 索引残留 / UNIQUE INDEX 存量校验 / SELECT * 别名投影 / WAL BEGIN/ROLLBACK 事务边界 / aria $in 与级联重复扫描性能 / $and 等值下推 / ANALYZE 索引统计 / React-Vue hooks 生命周期 / 迁移主键兜底 + 58 回归
This commit is contained in:
@@ -72,17 +72,23 @@ export function useDatabase(config: import('../constants').DatabaseConfig): {
|
||||
const [db, setDb] = useState<MetonaSqlark | null>(null);
|
||||
const [ready, setReady] = useState(false);
|
||||
const [error, setError] = useState<Error | null>(null);
|
||||
const initRef = useRef(false);
|
||||
// v0.7.3: config 变更时重建实例 —— 此前 initRef 只建一次,配置更新永不生效
|
||||
// (且旧实例残留)。以 config 序列化指纹为依赖:值不变不重建,变更时
|
||||
// cleanup 关闭旧实例(close 幂等,未完成 init 亦可安全关闭)再建新实例。
|
||||
const configKey = JSON.stringify(config);
|
||||
const prevKeyRef = useRef<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (initRef.current) return;
|
||||
initRef.current = true;
|
||||
if (prevKeyRef.current === configKey) return;
|
||||
prevKeyRef.current = configKey;
|
||||
setReady(false);
|
||||
setError(null);
|
||||
const instance = new MetonaSqlark(config);
|
||||
instance.init()
|
||||
.then(() => { setDb(instance); setReady(true); })
|
||||
.catch(setError);
|
||||
return () => { instance.close(); };
|
||||
}, []);
|
||||
}, [configKey]);
|
||||
|
||||
return { db, ready, error };
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
*/
|
||||
|
||||
import { MetonaSqlark } from '../core';
|
||||
import { ref, watch, onMounted, type Ref } from 'vue';
|
||||
import { ref, watch, onMounted, onUnmounted, type Ref } from 'vue';
|
||||
|
||||
/** useSqlarkQuery: 执行 SQL 查询 */
|
||||
export function useSqlarkQuery(
|
||||
@@ -81,5 +81,13 @@ export function useSqlarkDatabase(config: import('../constants').DatabaseConfig)
|
||||
}
|
||||
});
|
||||
|
||||
// v0.7.3: 组件卸载时关闭数据库 —— 此前实例永不 close(连接/锁/后端句柄泄漏)
|
||||
onUnmounted(() => {
|
||||
const instance = db.value;
|
||||
if (instance) {
|
||||
instance.close().catch(() => { /* 关闭失败不阻塞卸载 */ });
|
||||
}
|
||||
});
|
||||
|
||||
return { db, ready, error };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user