Token导航 LogoToken导航TokenDH.com
开发操作浏览器github未标认证来源可访问许可证需确认审计未展示

db-core%2fpersistence数据库核心%2f 持久性

Agent Skill

db-core%2fpersistence 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

198

周安装

8

GitHub Stars

3,720

下载量

62
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:db-core%2fpersistence(数据库核心%2f 持久性)
来源仓库:https://github.com/tanstack/db
仓库路径:skills/db-core%2Fpersistence
安装命令:
npx skills add https://github.com/tanstack/db --skill db-core/persistence
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/tanstack/db --skill db-core/persistence

简介

db-core/persistence 为 TanStack DB 添加 SQLite 持久化层,使数据在页面刷新后仍保持可用。

  • 它作为本地缓存加速首次加载,同时保持服务器权威性,支持离线编辑与断线重连恢复。
  • 使用时需选择平台包(如 browser-db-sqlite-persistence)并传入 persistence 实例至 collection。
  • 建议在生产环境启用加密选项,并定期清理过期条目以防止存储空间无限增长。
  • db-core%2fpersistence 属于开发类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

This skill builds on db-core and db-core/collection-setup. Read those first.

SQLite Persistence

TanStack DB persistence adds a durable SQLite-backed layer to any collection. Data survives page reloads, app restarts, and offline periods. The server remains authoritative for synced collections -- persistence provides a local cache that hydrates instantly.

Choosing a Platform Package

PlatformPackageCreate function
Browser (OPFS)@tanstack/browser-db-sqlite-persistencecreateBrowserWASQLitePersistence
React Native@tanstack/react-native-db-sqlite-persistencecreateReactNativeSQLitePersistence
Expo@tanstack/expo-db-sqlite-persistencecreateExpoSQLitePersistence
Electron@tanstack/electron-db-sqlite-persistencecreateElectronSQLitePersistence (renderer)
Node.js@tanstack/node-db-sqlite-persistencecreateNodeSQLitePersistence
Capacitor@tanstack/capacitor-db-sqlite-persistencecreateCapacitorSQLitePersistence
Tauri@tanstack/tauri-db-sqlite-persistencecreateTauriSQLitePersistence
Cloudflare DO@tanstack/cloudflare-durable-objects-db-sqlite-persistencecreateCloudflareDOSQLitePersistence

All platform packages re-export persistedCollectionOptions from the core.

Local-Only Persistence (No Server)

For purely local data with no sync backend:

import { createCollection } from '@tanstack/react-db'
import {
  BrowserCollectionCoordinator,
  createBrowserWASQLitePersistence,
  openBrowserWASQLiteOPFSDatabase,
  persistedCollectionOptions,
} from '@tanstack/browser-db-sqlite-persistence'

const database = await openBrowserWASQLiteOPFSDatabase({
  databaseName: 'my-app.sqlite',
})

const coordinator = new BrowserCollectionCoordinator({
  dbName: 'my-app',
})

const persistence = createBrowserWASQLitePersistence({
  database,
  coordinator,
})

const draftsCollection = createCollection(
  persistedCollectionOptions<Draft, string>({
    id: 'drafts',
    getKey: (d) => d.id,
    persistence,
    schemaVersion: 1,
  }),
)

Local-only collections provide collection.utils.acceptMutations() for applying mutations directly.

Synced Persistence (Wrapping an Adapter)

Spread an existing adapter's options into persistedCollectionOptions to add persistence on top of sync:

import { createCollection } from '@tanstack/react-db'
import { electricCollectionOptions } from '@tanstack/electric-db-collection'
import {
  createReactNativeSQLitePersistence,
  persistedCollectionOptions,
} from '@tanstack/react-native-db-sqlite-persistence'

const persistence = createReactNativeSQLitePersistence({ database })

const todosCollection = createCollection(
  persistedCollectionOptions({
    ...electricCollectionOptions({
      id: 'todos',
      shapeOptions: { url: '/api/electric/todos' },
      getKey: (item) => item.id,
    }),
    persistence,
    schemaVersion: 1,
  }),
)

This works with any adapter: electricCollectionOptions, queryCollectionOptions, powerSyncCollectionOptions, etc. The persistedCollectionOptions wrapper intercepts the sync layer to persist data as it flows through.

Multi-Tab / Multi-Process Coordination

Coordinators handle leader election and cross-instance communication so only one tab/process owns the database writer.

PlatformCoordinatorMechanism
BrowserBrowserCollectionCoordinatorBroadcastChannel + Web Locks
ElectronElectronCollectionCoordinatorIPC (main holds DB, renderer accesses via RPC)
Single-process (RN, Expo, Node, etc.)SingleProcessCoordinatorNo-op (always leader)

Browser example:

import { BrowserCollectionCoordinator } from '@tanstack/browser-db-sqlite-persistence'

const coordinator = new BrowserCollectionCoordinator({
  dbName: 'my-app',
})

// Pass to persistence
const persistence = createBrowserWASQLitePersistence({ database, coordinator })

// Cleanup on shutdown
coordinator.dispose()

Electron requires setup in both processes:

// Main process
import { exposeElectronSQLitePersistence } from '@tanstack/electron-db-sqlite-persistence'
exposeElectronSQLitePersistence({ persistence, ipcMain })

// Renderer process
import {
  createElectronSQLitePersistence,
  ElectronCollectionCoordinator,
} from '@tanstack/electron-db-sqlite-persistence'

const coordinator = new ElectronCollectionCoordinator({ dbName: 'my-app' })
const persistence = createElectronSQLitePersistence({
  ipcRenderer: window.electron.ipcRenderer,
  coordinator,
})

Schema Versioning

schemaVersion tracks the shape of persisted data. When the stored version doesn't match the code, the collection resets (drops and reloads from server for synced collections, or throws for local-only).

persistedCollectionOptions({
  // ...
  schemaVersion: 2, // bump when you change the data shape
})

There is no custom migration function -- a version mismatch triggers a full reset. For synced collections this is safe because the server re-supplies the data.

Key Options

OptionTypeDescription
persistencePersistedCollectionPersistencePlatform adapter + coordinator
schemaVersionnumberData version (default 1). Bump on schema changes
idstringRequired for local-only. Collection identifier in SQLite

Common Mistakes

CRITICAL Using local-only persistence without an id

Wrong:

persistedCollectionOptions({
  getKey: (d) => d.id,
  persistence,
  // missing id — generates random UUID each session, data won't persist across reloads
})

Correct:

persistedCollectionOptions({
  id: 'drafts',
  getKey: (d) => d.id,
  persistence,
})

Without an explicit id, the code generates a random UUID each session, so persisted data is silently abandoned on every reload. Local-only persisted collections must always provide an id. Synced collections derive it from the adapter config.

HIGH Forgetting the coordinator in multi-tab apps

Wrong:

const persistence = createBrowserWASQLitePersistence({ database })
// No coordinator — concurrent tabs corrupt the database

Correct:

const coordinator = new BrowserCollectionCoordinator({ dbName: 'my-app' })
const persistence = createBrowserWASQLitePersistence({ database, coordinator })

Without a coordinator, multiple browser tabs write to SQLite concurrently, causing data corruption. Always use BrowserCollectionCoordinator in browser environments.

HIGH Not bumping schemaVersion after changing data shape

If you add, remove, or rename fields in your collection type but keep the same schemaVersion, the persisted SQLite data will have the old shape. For synced collections, bump the version to trigger a reset and re-sync.

MEDIUM Not disposing the coordinator on cleanup

// On app shutdown or hot module reload
coordinator.dispose()
await database.close?.()

Failing to dispose leaks BroadcastChannel subscriptions and Web Lock handles.

See also: db-core/collection-setup/SKILL.md — for adapter selection and collection configuration.

See also: offline/SKILL.md — for offline transaction queueing (complements persistence).

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.36%
按下载量换算23

Claude

29.76%
按下载量换算18

Cursor

19.16%
按下载量换算12

Gemini CLI

9.71%
按下载量换算6

安全审计

暂无安全审计结果可展示。

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills