db-core/collection-setup

Centralize typed TanStack DB collection setup across multiple adapters.

3.9k|254|Updated Mar 11, 2025
One-click install
npx skills add https://github.com/TanStack/db --skill db-core-collection-setup
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: db-core/collection-setup
Source: https://github.com/TanStack/db/tree/main/packages/db/skills/db-core/collection-setup
Command: npx skills add https://github.com/TanStack/db --skill db-core-collection-setup

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Centralizes and streamlines the setup of typed TanStack DB collections across multiple adapters, reducing boilerplate and preventing type-adapter mismatches.

Core Features & Use Cases

  • Centralized collection creation with createCollection using adapters like REST query, Electric, PowerSync, RxDB, TrailBase, and local adapters.
  • Guidance on key configuration options such as getKey, schema, sync, gcTime, autoIndex, defaultIndexType, and syncMode, plus collection lifecycle states.
  • Includes adapter-specific patterns for txid tracking, direct writes, and onLoad/onLoadSubset hooks to keep data in sync.

Quick Start

Define a typed collection by choosing an adapter (e.g., queryCollectionOptions, electricCollectionOptions, or powerSyncCollectionOptions) and calling createCollection with a schema.

Frequently Asked Questions about db-core/collection-setup

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up typed TanStack DB collections with Electric or PowerSync adapters?

TanStack DB collection setup involves selecting an adapter like Electric or PowerSync and calling createCollection with a defined schema. This centralizes configuration, reducing boilerplate and preventing type-adapter mismatches across REST, RxDB, and local backends.

What configuration options are available when creating a TanStack DB collection?

Creating a TanStack DB collection supports configuration options including getKey, schema, sync, gcTime, autoIndex, defaultIndexType, and syncMode. It also provides lifecycle hooks like onLoad and onLoadSubset to keep data synchronized.

Can I use RxDB or TrailBase as a backend adapter for TanStack DB collections?

Yes, you can use RxDB or TrailBase as backend adapters for TanStack DB collections. The adapter pattern supports multiple backends including REST query, Electric, PowerSync, RxDB, TrailBase, and local adapters for flexible data synchronization.

How do adapter patterns handle data synchronization and lifecycle states in TanStack DB?

Adapter patterns handle data synchronization in TanStack DB by utilizing syncMode, txid tracking, and direct writes. Lifecycle states and hooks like onLoad and onLoadSubset ensure data remains consistently synced across the chosen backend adapter.

What is the best way to prevent type-adapter mismatches when wiring multiple DB collection backends?

The best way to prevent type-adapter mismatches is to centralize collection creation using createCollection. By enforcing a consistent structure with adapter-specific patterns and schemas, you ensure type safety across REST, Electric, PowerSync, and RxDB backends.