Skip to content

Enable Studio execute

Studio

Let Studio’s Playground run the SQL it generates against your database and show the rows. Execute is off by default. Turn it on with its own read-only connection, so a query Studio runs can’t change your data.

  • Studio running against your schema artifact. The Studio tour shows how to launch it.
  • Access to create a database role, or a connection string for a role that can only read.

Give Studio a role that can only read the tables you want to query. Run safely in production shows the grants for each engine. Put that role’s connection string in .env:

.env
STUDIO_READONLY_DATABASE_URL=postgres://studio_reader:<password>@localhost:5432/app

For SQLite, you need no role: Studio opens the file read-only.

Add studio.execute to askdb.config.ts:

askdb.config.ts
export default defineConfig({
// ...
studio: {
execute: {
enabled: true,
databaseUrl: env("STUDIO_READONLY_DATABASE_URL"), // or `file: "./data.db"` for SQLite
// timeoutMs: 30000, // per-query timeout (default 30 s)
// maxRows: 500, // row cap (default 500)
},
},
});

Studio runs queries on the same engine as introspection.provider. If you introspect a Prisma schema, or want to run on another engine, set provider too: "postgres", "mysql", "sqlite" or "sqlserver". Studio doesn’t reuse your introspection connection unless you set useIntrospectionConnection: true. Give execute the connection of a role that only reads. Configuration — Studio execute lists every field.

If you chose Studio execute in askdb init or the setup wizard, enabled: true is already there, but databaseUrl reads the same variable as introspection (DATABASE_URL unless you named another). Point it at the read-only role’s variable instead.

Studio needs the driver for its execute engine. If introspection already uses the same engine, the driver is installed:

Terminal window
npm install pg

You can also install it from the Playground in step 4: when the driver is missing, Studio shows an Install button for it, such as Install pg. It works only from the machine Studio runs on, and only in a project with a lockfile, which tells Studio the package manager. Otherwise it shows the command to run.

For SQL Server, databaseUrl takes any of the three formats introspection reads, because Studio converts it before it reaches mssql: see Write the connection string.

Restart Studio, so it reads the new config. In the Playground:

  1. Ask a question and click Generate SQL.
  2. Check the line next to Execute Query: it names the engine, says the connection is configured, and says the driver is ready, for example Postgres · URL configured · pg ready.
  3. Click Execute Query.

The rows appear under Results, with a line such as 25 rows · 6ms. If the query returned more than maxRows rows, Studio shows the first maxRows and says the result was cut.

What you seeFix
No Execute Query button, and Studio execute is off. To run generated SQL from the Playground, set studio.execute.enabled: true …Execute is still off, or Studio hasn’t restarted since you changed the config.
no URL (or no file) next to the buttondatabaseUrl (or file) is unset, or its variable is empty in .env.
pg missing (or another driver)Install the driver (step 3).
SQL rejected by the read-only guardrail (SQL_MULTI_STATEMENT): …AskDB’s SQL checks refused the statement, before it reached the database. The rule in parentheses says why.
canceling statement due to statement timeout (Postgres), or Query timed out after … ms.The query ran longer than timeoutMs.