@@ -7,7 +7,7 @@ use crate::auth::{
77 SpacetimeIdentityToken ,
88} ;
99use crate :: routes:: subscribe:: generate_random_connection_id;
10- use crate :: util:: { ByteStringBody , NameOrIdentity } ;
10+ pub use crate :: util:: { ByteStringBody , NameOrIdentity } ;
1111use crate :: { log_and_500, ControlStateDelegate , DatabaseDef , NodeDelegate } ;
1212use axum:: body:: { Body , Bytes } ;
1313use axum:: extract:: { Path , Query , State } ;
@@ -26,10 +26,11 @@ use spacetimedb::host::ReducerOutcome;
2626use spacetimedb:: host:: UpdateDatabaseResult ;
2727use spacetimedb:: identity:: Identity ;
2828use spacetimedb:: messages:: control_db:: { Database , HostType } ;
29+ use spacetimedb_client_api_messages:: http:: SqlStmtResult ;
2930use spacetimedb_client_api_messages:: name:: { self , DatabaseName , DomainName , PublishOp , PublishResult } ;
3031use spacetimedb_lib:: db:: raw_def:: v9:: RawModuleDefV9 ;
3132use spacetimedb_lib:: identity:: AuthCtx ;
32- use spacetimedb_lib:: { sats, Timestamp } ;
33+ use spacetimedb_lib:: { sats, Timestamp , ProductValue } ;
3334
3435use super :: subscribe:: { handle_websocket, HasWebSocketOptions } ;
3536
@@ -378,19 +379,19 @@ pub(crate) async fn worker_ctx_find_database(
378379
379380#[ derive( Deserialize ) ]
380381pub struct SqlParams {
381- name_or_identity : NameOrIdentity ,
382+ pub name_or_identity : NameOrIdentity ,
382383}
383384
384385#[ derive( Deserialize ) ]
385386pub struct SqlQueryParams { }
386387
387- pub async fn sql < S > (
388- State ( worker_ctx) : State < S > ,
389- Path ( SqlParams { name_or_identity } ) : Path < SqlParams > ,
390- Query ( SqlQueryParams { } ) : Query < SqlQueryParams > ,
391- Extension ( auth) : Extension < SpacetimeAuth > ,
392- body : String ,
393- ) -> axum:: response:: Result < impl IntoResponse >
388+ pub async fn sql_direct < S > (
389+ worker_ctx : S ,
390+ SqlParams { name_or_identity } : SqlParams ,
391+ _params : SqlQueryParams ,
392+ auth : SpacetimeAuth ,
393+ sql : String ,
394+ ) -> axum:: response:: Result < Vec < SqlStmtResult < ProductValue > > >
394395where
395396 S : NodeDelegate + ControlStateDelegate ,
396397{
@@ -410,7 +411,20 @@ where
410411 . await
411412 . map_err ( log_and_500) ?
412413 . ok_or ( StatusCode :: NOT_FOUND ) ?;
413- let json = host. exec_sql ( auth, database, body) . await ?;
414+ host. exec_sql ( auth, database, sql) . await
415+ }
416+
417+ pub async fn sql < S > (
418+ State ( worker_ctx) : State < S > ,
419+ Path ( name_or_identity) : Path < SqlParams > ,
420+ Query ( params) : Query < SqlQueryParams > ,
421+ Extension ( auth) : Extension < SpacetimeAuth > ,
422+ body : String ,
423+ ) -> axum:: response:: Result < impl IntoResponse >
424+ where
425+ S : NodeDelegate + ControlStateDelegate ,
426+ {
427+ let json = sql_direct ( worker_ctx, name_or_identity, params, auth, body) . await ?;
414428
415429 let total_duration = json. iter ( ) . fold ( 0 , |acc, x| acc + x. total_duration_micros ) ;
416430
0 commit comments