انتقل إلى المحتوى
شعار أوراباسي
aurabase

SQL editor

Run SQL on your project from the browser, without a terminal: what the editor sends, what it keeps, and the rules it shares with aura db raw.

دليل عملي6 د قراءةالمستوى مبتدئ

هذه الصفحة غير متوفرة بلغتك بعد. يتم عرضه باللغة الإنجليزية.

The SQL editor of the Studio runs SQL on your project's database from the browser. It sends your query to the same endpoint as aura db raw, so it accepts and refuses the same statements, and it runs with administrator rights: row level security does not filter what it returns.

Prerequisites#

  • A project, and access to it in the Studio as a member of its organization.

  • For the CLI examples at the end: a linked project (aura link <project-id>) and the example schema, installed with the service role key of the project:

    export AURABASE_SERVICE_ROLE_KEY=aura_sk_…
    aura db seed --example docs

    It creates profiles, orgs, org_members, posts, todos, the view open_todos and the function todo_count(p_user uuid). See Example schema.

The Studio screens are described from the Studio code; the replayed examples on this page are the CLI ones, which call the same endpoint.

Open the editor#

In the Studio, open your project, then Database and SQL Editor in the database sidebar, or press the command palette shortcut and type SQL Editor. The page address is:

https://<studio>/<project-id>/database/sql/editor

The page has three areas: a sidebar with the History and Ask AI tabs, the editor, and the results below it.

Run a query#

  1. Type your SQL in the editor. A new query starts with the comment -- Write your SQL here.
  2. Click Run, or press ⌘ + Enter (Ctrl + Enter on Windows and Linux).
  3. Read the rows in the results table, with the row count and the time the request took.

Several statements separated by ; run in one request and one transaction: if one fails, none is applied. The results table shows the rows of the request; a statement that returns no row shows Query executed successfully — no records returned.

After a statement that changes the schema (create, alter, drop…), the other Studio pages of the project reload the schema, so a new table appears in the table editor without a page refresh.

What the editor runs#

RuleDetail
EndpointPOST /v1/db/{project_id}/raw, the endpoint of aura db raw and db.sql().
RightsThe project's administrator role: every row of every table, policies not applied.
Refused statementsThe same list as aura db raw: begin/commit, create extension, system catalogs, security definer functions, update or delete without where, and the others listed in Run SQL.
Time limitThe statement timeout of the endpoint, and the gateway stops waiting after 30 seconds by default.
Rate limitThe /raw limit of the project's plan applies to the editor as to the CLI.

To see what a user or a visitor would get, run the query with aura db raw --as authenticated --user <id> or --as anon (Run SQL); the editor has no such option.

Dry run and read only#

Two check boxes above the editor restrict the next run:

  • Dry run: the query is executed, then its transaction is rolled back. You see the rows and the errors it would produce, and nothing is kept. A banner above the results says that the transaction was canceled.
  • Read only: the transaction is opened read-only; PostgreSQL refuses any write.

The banner describes the mode of the run whose results are shown, even if you change the boxes afterwards. Use Dry run before an update or a migration you are not sure of.

Results and export#

  • Columns are shown in alphabetical order, not in the order of your select: each row arrives as a JSON object with sorted keys.
  • null values are marked as such; JSON values are shown as JSON text.
  • JSON copies the rows to the clipboard as a JSON array; CSV downloads them as query_<timestamp>.csv.
  • Copy copies the SQL; Export downloads it as a .sql file.

The results table shows every row the request returns. For large exports, prefer aura db raw --json or a direct connection with COPY (Connect to your database).

History#

The History tab lists your last 50 queries, each marked as succeeded or failed; click one to load it in the editor. The history is kept in your browser's local storage, per project: it is not shared with teammates or other devices, it is cleared with the browser's site data, and entries older than 30 days or longer than 10 KB are not kept. The trash icon clears it; the plus icon starts a new query.

Saved, shared or named queries are not available. Keep the queries you reuse in files of your repository, or as migrations (Run SQL).

Ask AI#

The Ask AI tab turns a question in plain language into SQL. Type the question and click Generate: the answer shows the SQL, the tables it uses, a confidence score and an explanation. If the model wrote no LIMIT, the server adds one and the panel says so (LIMIT <n> automatically added). Insert into editor copies the SQL into the editor; nothing runs until you click Run.

  • The server reads the schema of your project itself; it is not sent from the browser.
  • Ask AI needs an AI provider key: one saved for the project (POST /v1/ai/{project_id}/providers/openai), or one set on the server. Without it, the panel shows an AI_PROVIDER_NOT_CONFIGURED error saying that the provider openai is configured neither for the project nor on the server.
  • The last 20 questions and their SQL are kept in your browser, per project, for 30 days.

Read the generated SQL before running it: it runs with administrator rights like any query of the editor.

The same from the CLI#

The editor's modes are the --dry-run and --read-only options of aura db raw, which needs the project's service_role key in AURABASE_SERVICE_ROLE_KEY:

aura db raw --dry-run "update todos set done = true where title = 'Create a table' returning title, done"
aura db raw "select done from todos where title = 'Create a table'"
  ℹ Mode: dry-run — query is executed then transaction ROLLED BACK.
  done │ title
  ─────┼───────────────
  true │ Create a table

  ℹ 1 row(s).
  done
  ─────
  false

  ℹ 1 row(s).
aura db raw --read-only "delete from todos where title = 'Create a table'" || true
  ℹ Mode: read-only — PostgreSQL will reject any write.
Error: [400] BAD_REQUEST: Invalid request: cannot execute DELETE in a read-only transaction

Result#

After the dry run and the refused read-only delete, the row is unchanged:

aura db raw "select title, done from todos where title = 'Create a table'"
  done  │ title
  ──────┼───────────────
  false │ Create a table

  ℹ 1 row(s).

Common errors#

MessageCauseFix
Operation not allowed in a raw query: transaction control …begin, commit or rollback in the query.Remove them: each run is already one transaction.
UPDATE without a WHERE clause is not allowed in raw queries … or DELETE without a WHERE clause …An update or a delete without where.Add a where (where true to change or delete every row on purpose).
cannot execute … in a read-only transactionRead only is checked.Uncheck it to write.
The 'SECURITY DEFINER' option is not allowed in raw queries …Creating a definer function.Use the function API (Database functions).
AI_PROVIDER_NOT_CONFIGURED in Ask AINo AI provider key for the project or the server.Save a provider key for the project.
429The /raw rate limit of the plan.Wait for the next minute; batch statements in one run.

See also#

@aurabase/aurabase-js@0.7.5 · aura@0.3.4↗ الإبلاغ عن مشكلة