Skip to content

Commit 2c0ba8a

Browse files
committed
fix(rivetkit): drop is_read_only_sql classifier, surface RETURNING rows
1 parent 6ac729a commit 2c0ba8a

2 files changed

Lines changed: 8 additions & 36 deletions

File tree

  • rivetkit-rust/packages/rivetkit-core/src/registry
  • rivetkit-typescript/packages/rivetkit/src/registry

rivetkit-rust/packages/rivetkit-core/src/registry/inspector.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -495,18 +495,11 @@ impl RegistryDispatcher {
495495
Some(encode_json_as_cbor(&body.args)?)
496496
};
497497

498-
if is_read_only_sql(&body.sql) {
499-
let rows = ctx
500-
.db_query(&body.sql, params.as_deref())
501-
.await
502-
.context("run inspector read-only database query")?;
503-
return Ok(decode_cbor_json_or_null(&rows));
504-
}
505-
506-
ctx.db_run(&body.sql, params.as_deref())
498+
let rows = ctx
499+
.db_query(&body.sql, params.as_deref())
507500
.await
508-
.context("run inspector database mutation")?;
509-
Ok(JsonValue::Array(Vec::new()))
501+
.context("run inspector database statement")?;
502+
Ok(decode_cbor_json_or_null(&rows))
510503
}
511504
}
512505

@@ -609,14 +602,6 @@ pub(super) fn quote_sql_identifier(identifier: &str) -> String {
609602
format!("\"{}\"", identifier.replace('"', "\"\""))
610603
}
611604

612-
pub(super) fn is_read_only_sql(sql: &str) -> bool {
613-
let statement = sql.trim_start().to_ascii_uppercase();
614-
matches!(
615-
statement.split_whitespace().next(),
616-
Some("SELECT" | "PRAGMA" | "WITH" | "EXPLAIN")
617-
)
618-
}
619-
620605
pub(super) fn json_http_response(
621606
status: StatusCode,
622607
payload: &impl Serialize,

rivetkit-typescript/packages/rivetkit/src/registry/native.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3448,9 +3448,6 @@ export function buildNativeFactory(
34483448
{ status: 400 },
34493449
);
34503450
}
3451-
const readOnly = /^\s*(SELECT|PRAGMA|WITH|EXPLAIN)\b/i.test(
3452-
body.sql,
3453-
);
34543451
if (
34553452
body.properties &&
34563453
typeof body.properties === "object" &&
@@ -3459,24 +3456,14 @@ export function buildNativeFactory(
34593456
const bindings = normalizeSqlitePropertyBindings(
34603457
body.properties as Record<string, unknown>,
34613458
);
3462-
if (readOnly) {
3463-
const rows = queryRows(
3464-
await actorCtx.sql.query(body.sql, bindings),
3465-
);
3466-
return jsonResponse({ rows: jsonSafe(rows) });
3467-
}
3468-
await actorCtx.sql.run(body.sql, bindings);
3469-
return jsonResponse({ rows: [] });
3470-
}
3471-
const args = Array.isArray(body.args) ? body.args : [];
3472-
if (readOnly) {
34733459
const rows = queryRows(
3474-
await actorCtx.sql.query(body.sql, args),
3460+
await actorCtx.sql.query(body.sql, bindings),
34753461
);
34763462
return jsonResponse({ rows: jsonSafe(rows) });
34773463
}
3478-
await actorCtx.sql.run(body.sql, args);
3479-
return jsonResponse({ rows: [] });
3464+
const args = Array.isArray(body.args) ? body.args : [];
3465+
const rows = queryRows(await actorCtx.sql.query(body.sql, args));
3466+
return jsonResponse({ rows: jsonSafe(rows) });
34803467
}
34813468
if (
34823469
url.pathname === "/inspector/summary" &&

0 commit comments

Comments
 (0)