feat(sql-editor): data peek, safe SQL bridge for Node cells, FK correctness fixes - #121
Merged
Merged
Conversation
Three strands of work, all in the SQL editor / core provider layer.
**Data peek (new).** Cmd/Ctrl-click a table in the schema explorer to see
its rows without writing a query. Foreign-key cells render as links; clicking
one appends the parent's rows as another grid below, so a relationship can be
followed a couple of hops. Breadcrumb navigates back. Answers "I just want a
quick look before I write the real query".
**`sql` bridge for `-- @node` cells (new).** Node code cells can now run SQL
against the run's credential via a tagged template whose interpolations become
bind parameters, never text:
await sql`INSERT INTO ${sql.id('accounts')} ${sql.values(rows)}`;
String interpolation was considered and rejected: a value containing an
apostrophe breaks the statement, null becomes the bare word null, Date becomes
a locale string, and an object becomes "[object Object]". Cells run in an
isolated worker with no DB handle, so `sql` proxies to the API process over a
request/response bridge. Three consequences worth knowing:
- The cell timeout pauses while a bridged query is in flight — database time
is not the cell's time, and without this any real migration was killed
mid-statement.
- Safe mode is enforced server-side per statement, since a cell cannot be
statically analyzed for the SQL it will build at runtime.
- Each `await sql` is its own round trip on a pooled connection, so
transactions and temp tables do not carry across calls.
**Foreign-key correctness (fixes).** `resolveFkReferencedColumns` now requires
every catalog entry to be a real identifier, not just matching arity — SQLite's
PRAGMA reports NULL for `to`, which arrived as `[null]` and produced
`REFERENCES parent ()`. A shared `groupForeignKeyRows` replaces the same
hand-rolled fold in five providers so that rule lives in one place. The
generator's new `referencesClause` emits a bare `REFERENCES parent` when the
parent columns are unknown, which every engine reads as "the parent's PK".
Also fixed along the way:
- SQLite adapter could never execute a write: it called `.all()` for every
statement and opened the file read-only. No SQLite connection could run DDL
or DML through any path.
- Blueprint modal: silent wrong-column FK guess, stripped schema qualifier,
self-referencing FKs unauthorable, misleading "applied" on skipped
statements, Oracle trigger timing missing EACH ROW.
- Ten sample bookmarks crashed with a raw TypeError when run standalone from
the statement strip (`last` is null there).
Samples gained five `sql`-bridge examples and a show/hide toggle. Every sample
is executed against a real database by its test, and `/sql/execute` now accepts
bind parameters.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_69e45237-1dc0-4fba-ad16-7ae3b58fcaed) |
|
|
||
| it('keeps null / Date / object as bound values, not text', () => { | ||
| const d = new Date('2026-01-02T03:04:05Z'); | ||
| const out = renderSqlQuery(sql`INSERT INTO t VALUES (${null}, ${d}, ${{ a: 1 }})`, 'mysql'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three strands of SQL-editor / core work. Each is independently reviewable; the FK fixes underpin the other two.
Data peek (new)
Cmd/Ctrl-click a table in the schema explorer to see its rows without writing a query. Foreign-key cells render as links — clicking one appends the parent's rows as a grid below, so a relationship can be followed a couple of hops. A breadcrumb walks back.
Answers the "I just want a quick look before I write the real query" case.
sqlbridge for-- @nodecells (new)Node code cells can now run SQL against the run's credential:
Interpolations become bind parameters, never text. String interpolation was requested and deliberately not used: an apostrophe in a value breaks the statement,
nullbecomes the bare word null,Datebecomes a locale string, and an object becomes[object Object].sql.raw()is the explicit escape hatch.Cells run in an isolated worker with no DB handle, so
sqlproxies to the API process over a request/response bridge. Three consequences reviewers should know:await sqlis its own round trip on a pooled connection, so transactions and temp tables do not carry across calls.sql.transaction()is the follow-up if that's needed./sql/executenow accepts bind parameters (a thin passthrough —executeOnConnectionalready took them).Foreign-key correctness (fixes)
resolveFkReferencedColumnsrequires every catalog entry to be a real identifier, not just matching arity. SQLite'sPRAGMA foreign_key_listreports NULL forto, which arrived as[null]and producedREFERENCES parent ().groupForeignKeyRowsreplaces the same hand-rolled fold in five providers, so that rule lives in one place instead of being re-derived per dialect..all()for every statement and opened the file read-only. No SQLite connection could run DDL or DML through any path, not just this feature.EACH ROW.Samples
Five
sql-bridge examples, plus a show/hide toggle for the built-in ★ samples (a view filter — they stay installed). Ten existing samples crashed with a raw TypeError when run standalone from the statement strip, wherelastis null; all now guard, with a test that runs every browser sample withlast: null.Rebase note
This work was developed against
bd614e1605and rebased onto current main, which had independently refactored several of the same files. Two resolutions worth a look:sql-generator.module.ts— main addedaddForeignKeySql, which handles the empty-parent-columns case by emitting a-- review: skip FKcomment. I took main's version and dropped myreferencesClause(which emitted a bareREFERENCES parent). Main's is the more conservative choice; my upstream fixes make its skip path trigger far less often.SqlSchemaExplorer.tsx— main refactored it substantially, so I took main's file wholesale and re-applied only the peek feature, dropping mypreferredIdsmemo tweak in favour of main's equivalent.Verification
cd apps/web && npx tsc --noEmitclean;npx vitest run(repo root) 607 passed, 2 skipped; ESLint clean on touched files.DELETEand the rows were verified still present, and an infinite-loop cell was terminated by the timeout.customers · id = 3.One caught in self-review worth flagging: the FK link handler was passing the 1-based display row number where a row index was expected, so most links silently drilled the wrong row or did nothing. The original fixture masked it (two rows shared a customer_id); reseeding with distinct values exposed it. Fixed and verified.
🤖 Generated with Claude Code
Note
High Risk
Changes user-code SQL execution (worker bridge, unbounded DB time during paused timeouts), ad-hoc query binding, and SQLite write behavior—security- and data-integrity sensitive paths that need careful review.
Overview
Data peek — Cmd/Ctrl-click a table/view/MQT in the schema explorer opens a modal that loads up to 50 rows via parameterized
SELECT *. FK columns render as links; clicking stacks another grid below with a breadcrumb to walk back.DataGridgains optional FK link rendering; the store owns peek state and usestablePreviewhelpers.Node
sqlbridge — New@foxschema/coresqlTag/renderSqlQueryturns tagged-template values into bind parameters per dialect. The code-cell worker exposessqlto user code but runs statements in the API viacell-querymessages;makeCellQueryRunnerenforces Safe mode writes, caps rows, and the cell timeout pauses while queries are in flight./sql/code-cellresolves a connection ref when present; the editor passesrefandallowWriteson runs./sql/executeandrunStatementsaccept optionalparamsper statement.FK & provider fixes —
resolveFkReferencedColumnsignores NULL/empty catalog parent columns; sharedgroupForeignKeyRowsreplaces duplicated provider logic (incl. Redshift FK query fallback). SQLite adapter opens read-write, usesfileMustExist, and runs non-reader statements withrun().Editor polish — Blueprint modal FK/Oracle trigger/apply messaging fixes; bookmark sample hide toggle; sample cells guard
last === null; new Nodesqlsamples and user-guide docs;.gitignorefor localfoxflow.sqlite*.Reviewed by Cursor Bugbot for commit 0d03e73. Bugbot is set up for automated code reviews on this repo. Configure here.