Keep your team's SQL snippets in one base.
The queries your team keeps rewriting — safe upserts, keyset pagination, latest-row-per-group — are exactly the ones that go subtly wrong when someone re-derives them at 6pm before a deploy. The-Snip keeps them once, reviewed and searchable, next to the saved API calls and runbooks that use them. Weighted full-text search finds the right query by title in a keystroke, and your AI agents can pull the same canonical SQL over REST and MCP instead of hallucinating an OFFSET-based paginator. When an agent proposes a new query, it waits in review until a human approves it into canon.
SQL snippets worth keeping
Idempotent upsert
INSERT INTO users (email, name)
VALUES ('sara@example.com', 'Sara')
ON CONFLICT (email) DO NOTHING;Insert or skip on conflict — safe to re-run seeds and imports. Swap DO NOTHING for DO UPDATE SET when you want last-write-wins instead.
Keyset pagination
SELECT id, title, created_at
FROM items
WHERE created_at < $1
ORDER BY created_at DESC
LIMIT 20;Stable, index-friendly paging — no OFFSET drift when rows are inserted mid-scroll, and no page-1000 slowdown. The cursor is just the last row's created_at.
Latest row per group
SELECT DISTINCT ON (user_id) user_id, status, created_at
FROM events
ORDER BY user_id, created_at DESC;Most-recent event per user in one pass. DISTINCT ON is the Postgres idiom everyone forgets exists and then rewrites badly with a self-join.
Weighted full-text rank
SELECT id, ts_rank_cd(search, q) AS rank
FROM items, websearch_to_tsquery('english', $1) q
WHERE workspace_id = $2 AND search @@ q
ORDER BY rank DESC
LIMIT 20;Title matches outrank body matches — this is literally the pattern behind The-Snip's own search, tenant-scoped by workspace_id in the same WHERE clause.
Batched delete
DELETE FROM events
WHERE id IN (
SELECT id
FROM events
WHERE created_at < now() - interval '90 days'
ORDER BY created_at
LIMIT 10000
);Purge old rows in bounded bites instead of one giant DELETE that bloats WAL and holds locks. Loop it from a job until it reports zero rows deleted.
Questions, answered.
Can I store the query and the API call that uses it together?
Yes — snippets, saved API calls and Markdown docs live in one base, cross-linked with [[wikilinks]]. The migration runbook links the exact queries it runs; the endpoint doc links the curl that exercises it.
Is search fast on SQL snippets?
Yes — weighted full-text search across snippets, APIs and docs, scoped to your workspace, with trigram matching so a typo in "pagination" still finds it. The weighted-rank example on this page is the same pattern the product runs on.
Which SQL dialects highlight correctly?
The SQL grammar covers Postgres, MySQL and standard SQL cleanly — the same grammar VS Code uses, rendered server-side. Dialect-specific keywords like DISTINCT ON or ON CONFLICT render fine.
Can agents propose new queries?
Yes — over REST or MCP (reads are free on every plan; agent writes need the one Pro & Team plan, $8/user/month). An agent that derives a useful query mid-task files it with create_snippet; it sits in review until a human confirms it's correct. Nobody's production data meets an unreviewed agent query by accident.
Is my team's base isolated from other tenants?
Yes. Every query the product runs is workspace-scoped at the SQL layer — search never crosses tenant boundaries — and API keys are hashed at rest and scoped to a single workspace.
Start your base — free.
Free: 25 items, no card. Pro & Team: $8/user/mo — unlimited items, REST API, review workflow, and the hosted MCP server.