database-patterns

database-patterns is a cursor rule for Cursor from brendadeeznuts1111/betting-brain-v3. It costs 2,036 tokens per session, scanned A, original, MIT.

Rules for using Cloudflare D1, a SQL database service, including how to prepare queries, bind values, read results, and normalize them.

In plain words
What is it for?
Use them to find database operations, parameterized queries, result-reading calls, and D1 database bindings in the code.
Why use it?
They encourage consistent database access and make queries easier to search, review, and handle safely.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/brendadeeznuts1111/betting-brain-v3/database-patterns
Clone the repo
git clone --depth 1 https://github.com/brendadeeznuts1111/betting-brain-v3

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for database-patterns

README.md
[![agentmods](https://agentmods.dev/badge/rules/brendadeeznuts1111/betting-brain-v3/database-patterns.svg)](https://agentmods.dev/rules/brendadeeznuts1111/betting-brain-v3/database-patterns)
Your own site
<a href="https://agentmods.dev/rules/brendadeeznuts1111/betting-brain-v3/database-patterns"><img src="https://agentmods.dev/badge/rules/brendadeeznuts1111/betting-brain-v3/database-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 2,036 This file is loaded in full into every session.
When invoked 2,036 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.02036 $0.02036
Opus 5 $0.01018 $0.01018
Sonnet 5 $0.00407 $0.00407
Haiku 4.5 $0.00204 $0.00204

Measured 5d ago against content hash 6c2870855ffe, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

database-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/database-patterns.mdc · 314 lines

How it starts

The opening of the file, as written. The whole thing — 314 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Database Patterns

🔍 Code Searchability Patterns

Find database-patterns Issues with ast-grep

# Find env.$DB.prepare($QUERY)
# Find await stmt.bind($$$).all()
# Find await stmt.bind($$$).first()
# Find normalizeD1Result<$$$>($$$)
ast-grep --pattern 'env.$DB.prepare($QUERY)' src/
ast-grep --pattern 'await stmt.bind($$$).all()' src/
ast-grep --pattern 'await stmt.bind($$$).first()' src/
ast-grep --pattern 'normalizeD1Result<$$$>($$$)' src/
sg -p 'env.$DB.prepare($QUERY)' src/
sg -p 'await' src/
sg -p 'await' src/
sg -p 'normalizeD1Result<$$$>($$$)' src/

database-patterns Discovery Commands

sg search "env.ANALYTICS.prepare" src/
sg search "normalizeD1Result" src/
sg search ".bind(" src/
sg search ".all()" src/

Search Examples

# Find all database queries
sg search 'env.$DB.prepare($QUERY)' src/
# Find D1 result normalization
sg search 'await' src/
# Find parameterized queries
sg search 'await' src/
# Find query execution patterns
sg search 'normalizeD1Result<$$$>($$$)' src/

D1 Database Usage

Environment Bindings

Primary Databases:

  • ANALYTICS - Main betting analytics database
  • RAW_FEED_DB - Raw feed database

Configuration: wrangler.toml

Query Patterns

Parameterized Queries (CRITICAL)
// ✅ CORRECT: Parameterized query
const result = await env.ANALYTICS.prepare(`
  SELECT * FROM line_movements 
  WHERE eid = ? AND ts > ?
  LIMIT ?
`).bind(eventID, timestamp, limit).all();

// ❌ WRONG: String interpolation (SQL injection risk)
const result = await env.ANALYTICS.prepare(`
  SELECT * FROM line_movements 
  WHERE eid = '${eventID}' AND ts > '${timestamp}'
  LIMIT ${limit}
`).all();
Type Safety
import { normalizeD1Result } from '../utils/request';

// Query with type conversion
const result = await env.ANALYTICS.prepare(`
  SELECT eid, mt, ts, old_line, new_line
  FROM line_movements
  WHERE eid = ?
  ORDER BY ts DESC
  LIMIT ?
`).bind(eventID, limit).all();

// Normalize with proper typing
type Movement = {
  eid: string;
  mt: string;
  ts: string;
  old_line: number;
  new_line: number;
};

const movements = normalizeD1Result<Movement>(result);

Read the full file on GitHub · 314 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 314 lines · 2,036 tokens per session scan A 6c2870855ffe

Subscribe to this mod's changes

database-patterns is a cursor rule published in the GitHub repository brendadeeznuts1111/betting-brain-v3 (8 stars, last pushed 11mo ago), licensed MIT. It adds 2,036 tokens to every session, about $0.0102 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.