Server Beam: Moving Data Between Two Databases with SQL and JavaScript

Server Beam is the SQL Editor feature for moving data between two different database servers inside a single script, mixing SQL and JavaScript with async/await. It exists for the case a normal query can't handle: copying, reshaping, or reconciling rows across two live connections in one run.

How it's triggered

Server Beam isn't a separate mode you switch on — it's detected automatically. Check two connections in your Destinations list, write a -- @node code block that calls sql.on('source') or sql.on('target'), and Run resolves those aliases to whichever two connections you checked, in order: the first checked is source, the second is target. FoxSchema always states the mapping out loud in the run output, because a beam writing to the wrong database is the one mistake this feature can cause:

Server Beam → source = staging-oltp, target = analytics-warehouse

Check more than two and the run stops with a warning to uncheck the extras rather than guessing which two you meant.

A minimal example

A read-only ping against both servers, safe to run with Safe mode on:

-- @node
const fromSource = await sql.on('source')`SELECT 1 AS n, 'source' AS hop`;
const fromTarget = await sql.on('target')`SELECT 1 AS n, 'target' AS hop`;

return [
  { hop: 'source', n: fromSource[0]?.n },
  { hop: 'target', n: fromTarget[0]?.n },
];
-- @end

Copying rows across servers

The more realistic case reads from one server, transforms in JavaScript, and writes to the other — all as bind parameters, never string-built SQL:

-- @node
const src = await sql.on('source')`SELECT id, email FROM accounts`;
const rows = src.map((r) => ({
  id: r.id,
  email: String(r.email).toLowerCase(),
  domain: String(r.email).split('@')[1] ?? '',
}));

await sql.on('target')`
  INSERT INTO ${sql.id('accounts')} ${sql.values(rows)}
`;
-- @end

Turn Safe mode off for this one, since it writes on the target. Reads stay Safe-mode friendly.

The limits, and why they're there

Server Beam caps at 2 servers and 20 SQL bridge calls (any sql or sql.on query) per Execute. Each call is its own round trip and may land on a different pooled connection, so transactions and temp tables don't carry across calls — design scripts as a sequence of independent statements, not one long transaction spanning two servers. These aren't arbitrary throttles: unbounded fan-out across arbitrary servers from a browser-triggered script is exactly the kind of thing worth capping by default.

When to reach for it instead of Data migrate

The SQL Editor's row-level Data migrate flow (compare two Destinations side by side, pick Add/Edit/Delete, apply) covers up to 500 row operations with a guided UI and no code. Past that cap, FoxSchema points you at Server Beam instead — it's the tool for larger transfers, custom reshaping mid-copy, or moving data on a schedule rather than through a grid.

The SQL Editor sidebar's Bookmarks → Add samples includes ready-made Server Beam scripts (ping and chunked copy) to start from. If the two servers you're beaming between don't share a schema yet, run a schema comparison first so the target table actually matches what you're about to insert. See the documentation for the full reference, or install FoxSchema to try it.

Scroll to Top