agentsclimarketplace

Dexie

Skill phucbm/skills/skills/backend/dexie

Claude Plugin - Personal knowledge base for Claude Code — patterns and integrations across projects

Install
npx -y skills add phucbm/skills --skill dexie

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 2 stars2 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Dexie.js usage in a local-first Next.js + React + TypeScript app (IndexedDB wrapper, useLiveQuery, schema versioning, migrations)

SKILL.md

3.6 KB, as published. Nobody here has run it

Dexie.js — Local-First Patterns

Why Dexie

  • Wraps IndexedDB with a clean Promise/async-await API
  • useLiveQuery() auto-rerenders React components on data changes (no extra state management)
  • Schema versioning with .upgrade() handles migrations for existing user data
  • Typed tables via Table<T, PrimaryKey> — full TypeScript support
  • IndexedDB storage cap: gigabytes (vs localStorage ~5 MB)

Setup

pnpm add dexie dexie-react-hooks

Database definition (lib/db.ts)

import Dexie, { type Table } from 'dexie';

export interface Item {
  id?: number;
  name: string;
  createdAt: number;
}

class AppDatabase extends Dexie {
  items!: Table<Item, number>;

  constructor() {
    super('AppDatabase');
    this.version(1).stores({
      items: '++id, name',
    });
  }
}

export const db = new AppDatabase();
  • ++id — auto-increment primary key
  • Only index fields you query/sort by; non-indexed fields are still stored

Schema migration

this.version(1).stores({ items: '++id, name' });

this.version(2).stores({ items: '++id, name, category' }).upgrade(tx =>
  tx.table('items').toCollection().modify(item => {
    item.category = item.category ?? 'uncategorized';
  })
);
  • Always keep old versions — Dexie runs upgrades sequentially for users on older versions
  • .modify() mutates in place; return value is ignored

Querying

const all = await db.items.toArray();
const filtered = await db.items.where('name').equals('foo').toArray();
const sorted = await db.items.orderBy('createdAt').toArray();
const one = await db.items.get(id);

Writes

const id = await db.items.add({ name: 'Foo', createdAt: Date.now() });
await db.items.update(id, { name: 'Bar' });
await db.items.put({ id: 1, name: 'Bar', createdAt: Date.now() }); // upsert
await db.items.delete(id);

React integration — useLiveQuery

import { useLiveQuery } from 'dexie-react-hooks';
import { db } from '@/lib/db';

export function ItemList() {
  const items = useLiveQuery(() => db.items.toArray(), []);

  if (!items) return <p>Loading…</p>;
  return <ul>{items.map(i => <li key={i.id}>{i.name}</li>)}</ul>;
}
  • Returns undefined on first render — use as loading state
  • Second arg is dependency array — include any variables used inside the query
  • Re-renders automatically whenever the queried table changes

Transactions

await db.transaction('rw', db.items, async () => {
  await db.items.add({ ... });
  await db.items.update(someId, { ... });
});

Next.js / SSR constraint

  • Dexie only runs client-side — use 'use client' directive or guard with typeof window !== 'undefined'
  • Never call db.* in server components or static data-fetching functions

Gotchas

  • Index only what you filter/sort on — over-indexing wastes space and slows writes
  • useLiveQuery returns undefined initially — always handle the loading state
  • Compound index: '[field1+field2]' in .stores() for multi-field queries
  • Bulk ops: db.items.bulkAdd([...]) / db.items.bulkDelete([...]) for batch writes
  • Version must only increase — never reuse or decrement a version number

References

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.