Connections and safety
功能的Per-cell connections, environment badges, read-only by default, Allow writes, production prompts, trusting a notebook and remapping connections.
Every SQL cell runs on a connection: the notebook's, or one of its own. Whichever it is, the cell shows the connection and its environment, starts read-only, and needs your explicit go-ahead to change data. A notebook from somewhere else runs nothing until you trust it and say which connections it may use.
Per-cell connections
The top bar's Connection: … picker sets the notebook's connection; new cells use it. To run one cell somewhere else, select it and pick a connection in the inspector's 连接 field (or from the connection label in the cell header). Use the notebook's connection puts it back; a cell that follows the notebook shows its connection as "Storefront Dev (notebook)".
Each connection shows its environment badge, the same colours as the rest of SQLly: 生产, 预发布, 测试, 开发 或者 本地, set on the connection itself (see 环境). A notebook can compare development with production side by side, with each cell saying exactly where it ran.


Inside the file, a notebook refers to connections by slot: an id of its own, mapped to your saved connection by an opaque id. Server names, users and passwords are never written into a notebook. To read a result from a cell on a different connection, run the reading cell on the notebook's local data; see Join across connections.
Read-only by default
A new SQL cell is 只读. It runs on a copy of its connection with SQLly's read-only setting switched on, and on engines that have one, inside the database's own read-only session or transaction, so a statement that tries to write fails in the database even if SQLly's own check missed it. A read-only cell whose SQL plainly changes data is stopped before it is sent: "This cell is read-only and its SQL changes data. Choose Allow writes to run it."
Other kinds of cell that query a connection follow the same rule, with a few extra checks:
- Plan cells always capture their plan read-only, estimated or actual, and only for a single statement: "A plan can only be captured for a single statement. Split the query into one statement per cell." A query picked for comparison passes the same checks and must be on the same connection.
- Local cells and Materialize Locally never run a cell that may change data again to copy its rows. They use the complete result already on screen, or say "fix_freight changes data, so it is not run again to copy its rows. Run it yourself, then copy its complete result." Every other input they fetch again runs read-only.
- Diff cells that re-run a query on another connection need that connection allowed for the notebook and set up on this computer.
Results are filed under the connection, database, login and safety settings that fetched them. Switch a connection's sign-in, or its read-only setting, and earlier results are no longer current and saved ones aren't shown to the new login.
Cells in a notebook from an older SQLly version (.sqlnb.json) that change data come in with writes already allowed, so they keep working as they did; every cell you add starts read-only.
Allow writes
- 点击 Allow writes in the cell header (or clear 只读 in the inspector, or run Notebook: Allow Writes for Cell from the palette).
- SQLly asks "Let fix_freight change data?" and names the connection the cell runs on. On a production connection it adds "This is a production connection." Choose Allow writes,或 Keep read-only.
- The badge changes to Writes allowed,带有 Make read-only next to it to undo.
- When the cell runs, its statements still go through SQLly's change review, which says which connection and environment the change goes to ("On Storefront Prod (Production): …") and applies the connection's own rules: confirmation, refusing UPDATE or DELETE without WHERE, the production lock. The cell waits as Waiting for review until you answer.


A cell that changes data runs alone on its connection (the cells before it finish first), and notebooks with such cells can't be scheduled, viewed as a dashboard or presented. See 安全与护栏 for the connection-level settings the change review uses.
Trusting a notebook
Opening a notebook never runs anything. When a notebook came from somewhere else (another computer, a colleague, Git, Jupyter), or its queries or connections changed outside SQLly since you trusted it, a banner says so and nothing runs:
- "This notebook came from somewhere else. Nothing runs until you trust it and choose the connections it may use."
- "This notebook's queries or connections changed outside SQLLY since you trusted it. Review it and trust it again to run it."
- Read the cells. Everything is visible and editable before you trust.
- 按 Trust notebook on the banner (or Notebook: Trust Notebook in the palette).
- 在 Trust this notebook, check the connections under Connections it may use. Each line shows the connection on this computer it runs on and that connection's environment. Untick any the notebook shouldn't use.
- 选择 Trust (cells may run on the ticked connections) or Read-only trust (only cells that don't change data may run).
- 勾选 Allow cells that change data only if the notebook needs it. It starts unticked for a notebook from elsewhere.
- 按 Trust.


After that, the notebook stays trusted while you edit and save it in SQLly. Editing its Markdown or title elsewhere keeps it trusted; changing its SQL, its connections or a cell's read-only setting outside SQLly makes it untrusted again. A cell on a connection you unticked doesn't run, and the banner lists the connections still waiting ("This notebook isn't allowed to use these connections yet: …") with Allow connections. Under read-only trust the banner says "Trusted for read-only runs: cells that change data won't run." with Change trust.
More on what trust covers and how it's stored: Security model.
Remapping connections
A notebook made on another computer names connections by that computer's ids, which mean nothing here. SQLly shows "This notebook uses connections that are not on this computer. Choose one of yours for each:" with a Choose a connection picker per connection (labelled with the name and database the author used), and Skip for now. A cell whose connection isn't mapped shows Not on this computer and won't run until you map it.


Mapping is saved in the notebook when you save it. A connection you remap after trusting the notebook waits for your OK again, so pointing a notebook at production is always a decision you make, not a side effect of someone else's edit.
限制
- Whether SQL "changes data" is judged from its statements; a procedure call that writes can look like a read. The database's read-only session is the real guard for read-only cells, and connections marked read-only in SQLly stay read-only whatever a notebook says.
- "Use the tab's connection" in the top bar's connection menu moves every cell that follows the notebook's connection onto the tab's. While a cell is set to some other connection, it's refused ("Some cells use another connection, so the notebook keeps its saved connection. Set those cells to the notebook's connection first."), because that connection would otherwise become every cell's default.