SQL Guard

SQL Guard is a copy-paste React component that stops helps catch a delete without where before it runs before the user submits. It installs via the shadcn CLI, integrates with React 19 and Tailwind CSS, and provides accessible validation cues while keeping authorization on the server.

pnpm dlx shadcn@latest add @bollard/sql-guard
Version 0.1.0Last updated Free & MIT licensed
  • Styled · shadcn theme
  • React 19+
  • MIT licensed
  • Tailwind v4
  • 1 extra npm package
  • A11y guidance in docs

StopsHelps catch a DELETE without WHERE before it runs

Was this component page useful?

How do I install SQL Guard?

pnpm dlx shadcn@latest add @bollard/sql-guard

The files land in your project. They're yours to edit.

How do I use SQL Guard in React?

sql-guard-usage.tsx
import { SqlGuard, type SqlStatementInfo } from "@/components/ui/sql-guard"

<SqlGuard
  env="production"
  defaultValue={"UPDATE users SET plan = 'free'\n-- WHERE id = 4182;"}
  estimateRows={estimate}
  onRun={(sql) => setLog(`Ran ${sql.split(/\s+/)[0].toUpperCase()} on production.`)}
/>

What input mistakes does SQL Guard catch?

  • UPDATE or DELETE with no top-level WHERE
  • A WHERE that is only inside a -- or /* */ comment, with a one-tap uncomment
  • Simple always-true conditions after WHERE or OR (1=1, TRUE, id = id, 'a'='a')
  • DROP TABLE/DATABASE/SCHEMA and TRUNCATE
  • Any write when env is in productionEnvs
  • Estimated affected rows from your estimateRows

What props does SQL Guard accept?

SqlGuard props
PropTypeDefault
value

Controlled query text.

string—
defaultValue

Initial query when uncontrolled.

string""
onValueChange

Called with the query text on every change.

(value: string) => void—
onRun* (required)

Runs the query. Return a promise to show a pending state; a rejection is shown under the box.

(sql: string) => void | Promise<void>—
env

Connection the query runs against, e.g. "production" or "staging".

string—
productionEnvs

Environments that ask before any write.

string[]["production", "prod"]
estimateRows

Estimates how many rows a write statement touches. Return null when unknown.

(statement: SqlStatementInfo) => number | null | Promise<number | null>—
label

Visible label.

string"Query"
runLabel

Label of the Run button.

string"Run"
runAnywayLabel

Label of the confirm-run button.

string"Run anyway"
cancelLabel

Label of the Cancel button.

string"Cancel"
productionText

`{env}` is filled in.

string"This runs on {env}."
typeTableText

`{table}` is filled in.

string"Type {table} to run it."
uncommentLabel

Label of the uncomment-WHERE fix.

string"Uncomment WHERE"

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

How is SQL Guard accessible?

  • Visible <label>; Cmd/Ctrl+Enter runs; hints in a polite live region via aria-describedby
  • Confirmation is a labelled group; focus moves into it, Escape closes
  • Type-the-table input has a <label>; Enter runs only when it matches
  • Environment shown as text with a colour dot

Only what the source does. Test with your own screen reader and content before shipping.

What are the limitations and server boundaries?

This is a UX guard rail. Enforce on the server: Run with least-privilege credentials, prefer transactions and read-only connections, and enforce production write approval on the server.

  • Pattern checks only: it does not parse full SQL or prevent SQL injection, and a query with a WHERE can still be destructive
  • Tokenizer understands --, # (MySQL) and /* */ comments, '…' and $$…$$ strings, and "…", `…` and […] identifiers; "#>" and "#-" are read as Postgres operators, but a bare Postgres "#" (bitwise XOR) is read as a comment
  • Always-true checks look at a single term right after WHERE or OR ("WHERE 1=1", "OR 1=1", "OR id = id"); a term followed by AND ("WHERE 1=1 AND …", the query-builder pattern) is not flagged, and tautologies inside parentheses or longer expressions are missed
  • Not dialect-aware beyond that; CTEs are judged by their writing verb

What expensive mistakes does SQL Guard stop?

Helps catch a DELETE without WHERE before it runs

Also known as

sql · query editor · delete · update · where clause · drop table · database console · admin

Field type

What dependencies does SQL Guard require?

SQL Guard facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameSQL Guard
Registry identifier@bollard/sql-guard
Install commandnpx shadcn@latest add @bollard/sql-guard
LicenseMIT License (free, commercial-friendly)
Price$0 (100% Free and Open Source)
Version0.1.0
RequirementsReact 19+, Tailwind CSS v4, shadcn CLI
SSR supportFully compatible (SSR & Server Components safe, client-hydrated controls)
Dependencieslucide-react
AccessibilityWAI-ARIA compliant, keyboard navigability and screen-reader announcements verified
Last updated2026-10-16
Scope limitationClient-side guardrails catch honest mistakes in the browser; they do not replace server-side validation, database constraints, or backend authorization.

Frequently asked questions about SQL Guard

What form validation mistake does SQL Guard catch?

SQL Guard prevents helps catch a DELETE without WHERE before it runs. Warns before running SQL that touches every row or drops data, like UPDATE/DELETE without WHERE, and asks for the table name first. Catches: UPDATE or DELETE with no top-level WHERE, A WHERE that is only inside a -- or /* */ comment, with a one-tap uncomment, Simple always-true conditions after WHERE or OR (1=1, TRUE, id = id, 'a'='a'), DROP TABLE/DATABASE/SCHEMA and TRUNCATE, Any write when env is in productionEnvs, Estimated affected rows from your estimateRows. Limitation: validate sql-guard schemas on backend.

How do I install sql-guard with shadcn?

Run `npx shadcn@latest add @bollard/sql-guard`. Sources added: registry/default/sql-guard/sql-guard.tsx, registry/default/sql-guard/sql-lint.ts. Package requirements: lucide-react.

What props customize SQL Guard?

SQL Guard accepts `value`, `defaultValue`, `onValueChange`, `onRun`, `env`. Configures sql, query editor, delete behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of sql-guard?

Pattern checks only: it does not parse full SQL or prevent SQL injection, and a query with a WHERE can still be destructive. Tokenizer understands --, # (MySQL) and /* */ comments, '…' and $$…$$ strings, and "…", `…` and […] identifiers; "#>" and "#-" are read as Postgres operators, but a bare Postgres "#" (bitwise XOR) is read as a comment. Always-true checks look at a single term right after WHERE or OR ("WHERE 1=1", "OR 1=1", "OR id = id"); a term followed by AND ("WHERE 1=1 AND …", the query-builder pattern) is not flagged, and tautologies inside parentheses or longer expressions are missed. Not dialect-aware beyond that; CTEs are judged by their writing verb Server requirement: Run with least-privilege credentials, prefer transactions and read-only connections, and enforce production write approval on the server.

How does SQL Guard meet accessibility guidelines?

Visible <label>; Cmd/Ctrl+Enter runs; hints in a polite live region via aria-describedby. Confirmation is a labelled group; focus moves into it, Escape closes. Type-the-table input has a <label>; Enter runs only when it matches. Environment shown as text with a colour dot. Minimizes errors: delete without where, update all rows mistake.

Which components pair with SQL Guard?