@@ -6,7 +6,7 @@ use crate::auth::{
6
6
SpacetimeIdentityToken ,
7
7
} ;
8
8
use crate :: routes:: subscribe:: generate_random_connection_id;
9
- use crate :: util:: { ByteStringBody , NameOrIdentity } ;
9
+ pub use crate :: util:: { ByteStringBody , NameOrIdentity } ;
10
10
use crate :: { log_and_500, ControlStateDelegate , DatabaseDef , NodeDelegate } ;
11
11
use axum:: body:: { Body , Bytes } ;
12
12
use axum:: extract:: { Path , Query , State } ;
@@ -25,10 +25,11 @@ use spacetimedb::host::ReducerOutcome;
25
25
use spacetimedb:: host:: UpdateDatabaseResult ;
26
26
use spacetimedb:: identity:: Identity ;
27
27
use spacetimedb:: messages:: control_db:: { Database , HostType } ;
28
+ use spacetimedb_client_api_messages:: http:: SqlStmtResult ;
28
29
use spacetimedb_client_api_messages:: name:: { self , DatabaseName , DomainName , PublishOp , PublishResult } ;
29
30
use spacetimedb_lib:: db:: raw_def:: v9:: RawModuleDefV9 ;
30
31
use spacetimedb_lib:: identity:: AuthCtx ;
31
- use spacetimedb_lib:: sats;
32
+ use spacetimedb_lib:: { sats, ProductValue } ;
32
33
33
34
use super :: subscribe:: handle_websocket;
34
35
@@ -381,19 +382,19 @@ async fn worker_ctx_find_database(
381
382
382
383
#[ derive( Deserialize ) ]
383
384
pub struct SqlParams {
384
- name_or_identity : NameOrIdentity ,
385
+ pub name_or_identity : NameOrIdentity ,
385
386
}
386
387
387
388
#[ derive( Deserialize ) ]
388
389
pub struct SqlQueryParams { }
389
390
390
- pub async fn sql < S > (
391
- State ( worker_ctx) : State < S > ,
392
- Path ( SqlParams { name_or_identity } ) : Path < SqlParams > ,
393
- Query ( SqlQueryParams { } ) : Query < SqlQueryParams > ,
394
- Extension ( auth) : Extension < SpacetimeAuth > ,
395
- body : String ,
396
- ) -> axum:: response:: Result < impl IntoResponse >
391
+ pub async fn sql_direct < S > (
392
+ worker_ctx : S ,
393
+ SqlParams { name_or_identity } : SqlParams ,
394
+ _params : SqlQueryParams ,
395
+ auth : SpacetimeAuth ,
396
+ sql : String ,
397
+ ) -> axum:: response:: Result < Vec < SqlStmtResult < ProductValue > > >
397
398
where
398
399
S : NodeDelegate + ControlStateDelegate ,
399
400
{
@@ -413,7 +414,20 @@ where
413
414
. await
414
415
. map_err ( log_and_500) ?
415
416
. ok_or ( StatusCode :: NOT_FOUND ) ?;
416
- let json = host. exec_sql ( auth, database, body) . await ?;
417
+ host. exec_sql ( auth, database, sql) . await
418
+ }
419
+
420
+ pub async fn sql < S > (
421
+ State ( worker_ctx) : State < S > ,
422
+ Path ( name_or_identity) : Path < SqlParams > ,
423
+ Query ( params) : Query < SqlQueryParams > ,
424
+ Extension ( auth) : Extension < SpacetimeAuth > ,
425
+ body : String ,
426
+ ) -> axum:: response:: Result < impl IntoResponse >
427
+ where
428
+ S : NodeDelegate + ControlStateDelegate ,
429
+ {
430
+ let json = sql_direct ( worker_ctx, name_or_identity, params, auth, body) . await ?;
417
431
418
432
let total_duration = json. iter ( ) . fold ( 0 , |acc, x| acc + x. total_duration_micros ) ;
419
433
0 commit comments