appflare-querying

Read and write data in Appflare handlers using the typed ctx.db API.

Updated Sep 15, 2026
One-click install
npx skills add https://github.com/Imtiajrex/appflare-skills --skill appflare-querying-imtiajrex
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: appflare-querying
Source: https://github.com/Imtiajrex/appflare-skills/tree/main/skills/appflare-querying
Command: npx skills add https://github.com/Imtiajrex/appflare-skills --skill appflare-querying-imtiajrex

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires appflare, and includes references (resource) components.

What problem does it solve? Writing correct database logic inside Appflare handlers requires knowing the typed ctx.db API: which where operators exist, how to load relations, how to paginate, and how to keep concurrent writes atomic. This Skill teaches an AI agent those patterns so it generates correct queries, filters, aggregates, and multi-table writes instead of guessing. ## Core Features & Use Cases - Typed reads and filters: findMany and findFirst with operators like eq, in, gt, contains, exists, geoWithin, and/or/not combinators, relation loading with "with", orderBy, limit/offset, iterate, and cursor pagination. - Safe writes and concurrency: insert with nested relations, update with increment/decrement expressions, expectRows guards, atomic batch and transaction writes, upsert, and delete with ownership scoping. - Aggregates: count, sum, avg, min, max, and groupBy for dashboard-style statistics. - Use Case: While building a mutation handler that transfers balance between two accounts, the agent uses decrement with an expectRows guard inside ctx.db.batch so the transfer is atomic and fails cleanly on insufficient funds. ## Quick Start Ask the agent to write an Appflare query handler that lists a project's open tasks with assignee relations, search filtering, and cursor pagination using ctx.db.

Frequently Asked Questions about appflare-querying

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

FAQPage Schema
How do I filter rows with ctx.db in Appflare?▼

Pass a where object to findMany or findFirst using field operators like eq, ne, in, gt, gte, contains, startsWith, and exists, combined with and, or, and not combinators. Unknown operators or column names throw an AppflareQueryError, so check the schema field names first.

How do I paginate results in an Appflare query handler?▼

Use cursor pagination by filtering on the primary key (for example id less than the cursor), ordering by that column, and returning rows, nextCursor, and hasMore. For full scans, use iterate, which walks all rows with keyset pagination and no limit ceiling.

How do I update a counter or balance atomically in Appflare?▼

Use the increment and decrement SQL expressions in the update set clause instead of reading a value and writing it back in JavaScript. Add an expectRows guard so a non-matching where clause throws AppflareConflictError and writes nothing.

What is the difference between ctx.db.batch and ctx.db.transaction?▼

Use batch when all writes are known up front; the callback returns plans synchronously and results come back in order. Use transaction when a write depends on a read; writes inside it return handles whose rows are readable only after the transaction resolves.

Why does ctx.db update or delete throw without a where clause?▼

Update and delete throw when the where filter is missing or empty to prevent accidental full-table writes. Pass allowAll: true only when you intentionally want to affect every row.

When should I use ctx.$db instead of ctx.db in Appflare?▼

ctx.$db is the raw Drizzle escape hatch for queries the typed API cannot express. It skips runtime defaults, JSON handling, and realtime mutation events, so prefer ctx.db for normal reads and writes.