Files
digital-pilates/utils/kvStore.ts
richarjiang 2357596665 refactor(storage): 迁移 AsyncStorage 至 expo-sqlite/kv-store
- 统一替换所有 @react-native-async-storage/async-storage 导入为自定义 kvStore
- 新增 kvStore.ts 封装 expo-sqlite/kv-store,保持与 AsyncStorage 完全兼容
- 新增同步读写方法,提升性能
- 引入 expo-sqlite 依赖并更新 lock 文件

BREAKING CHANGE: 移除 @react-native-async-storage/async-storage 依赖,需重新安装依赖并清理旧数据
2025-09-15 12:51:18 +08:00

23 lines
1.2 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 直接使用 expo-sqlite/kv-store 作为 AsyncStorage 的替代品
// 这是 expo-sqlite 提供的现成 key-value store 实现,完全兼容 AsyncStorage API
import Storage from 'expo-sqlite/kv-store';
// 重新导出所有方法,保持与原 AsyncStorage 相同的接口
export const getItem = Storage.getItem.bind(Storage);
export const setItem = Storage.setItem.bind(Storage);
export const removeItem = Storage.removeItem.bind(Storage);
export const getAllKeys = Storage.getAllKeys.bind(Storage);
export const multiGet = Storage.multiGet.bind(Storage);
export const multiSet = Storage.multiSet.bind(Storage);
export const multiRemove = Storage.multiRemove.bind(Storage);
export const clear = Storage.clear.bind(Storage);
// 同步方法expo-sqlite/kv-store 的特色功能)
export const getItemSync = Storage.getItemSync.bind(Storage);
export const setItemSync = Storage.setItemSync.bind(Storage);
export const removeItemSync = Storage.removeItemSync.bind(Storage);
export const getAllKeysSync = Storage.getAllKeysSync.bind(Storage);
export const clearSync = Storage.clearSync.bind(Storage);
// 默认导出,与 AsyncStorage 接口完全兼容
export default Storage;