Skip to content

Commit 1683031

Browse files
committed
Pass CacheMode from /cubesql to backend
1 parent b1198a2 commit 1683031

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

packages/cubejs-api-gateway/src/gateway.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ class ApiGateway {
425425
try {
426426
await this.assertApiScope('data', req.context?.securityContext);
427427

428-
await this.sqlServer.execSql(req.body.query, res, req.context?.securityContext);
428+
await this.sqlServer.execSql(req.body.query, res, req.context?.securityContext, req.body.cache);
429429
} catch (e: any) {
430430
this.handleError({
431431
e,

packages/cubejs-api-gateway/src/sql-server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Request as NativeRequest,
99
LoadRequestMeta,
1010
Sql4SqlResponse,
11+
CacheMode,
1112
} from '@cubejs-backend/native';
1213
import type { ShutdownMode } from '@cubejs-backend/native';
1314
import { displayCLIWarning, getEnv } from '@cubejs-backend/shared';
@@ -65,8 +66,8 @@ export class SQLServer {
6566
throw new Error('Native api gateway is not enabled');
6667
}
6768

68-
public async execSql(sqlQuery: string, stream: any, securityContext?: any) {
69-
await execSql(this.sqlInterfaceInstance!, sqlQuery, stream, securityContext);
69+
public async execSql(sqlQuery: string, stream: any, securityContext?: any, cacheMode?: CacheMode) {
70+
await execSql(this.sqlInterfaceInstance!, sqlQuery, stream, securityContext, cacheMode);
7071
}
7172

7273
public async sql4sql(sqlQuery: string, disablePostProcessing: boolean, securityContext?: unknown): Promise<Sql4SqlResponse> {

packages/cubejs-backend-native/js/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,16 +429,18 @@ export const registerInterface = async (options: SQLInterfaceOptions): Promise<S
429429

430430
export type ShutdownMode = 'fast' | 'semifast' | 'smart';
431431

432+
export type CacheMode = 'stale-if-slow' | 'stale-while-revalidate' | 'must-revalidate' | 'no-cache';
433+
432434
export const shutdownInterface = async (instance: SqlInterfaceInstance, shutdownMode: ShutdownMode): Promise<void> => {
433435
const native = loadNative();
434436

435437
await native.shutdownInterface(instance, shutdownMode);
436438
};
437439

438-
export const execSql = async (instance: SqlInterfaceInstance, sqlQuery: string, stream: any, securityContext?: any): Promise<void> => {
440+
export const execSql = async (instance: SqlInterfaceInstance, sqlQuery: string, stream: any, securityContext?: any, cacheMode: CacheMode = 'stale-if-slow'): Promise<void> => {
439441
const native = loadNative();
440442

441-
await native.execSql(instance, sqlQuery, stream, securityContext ? JSON.stringify(securityContext) : null);
443+
await native.execSql(instance, sqlQuery, stream, securityContext ? JSON.stringify(securityContext) : null, cacheMode);
442444
};
443445

444446
// TODO parse result from native code

packages/cubejs-backend-native/src/node_export.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ async fn handle_sql_query(
226226
channel: Arc<Channel>,
227227
stream_methods: WritableStreamMethods,
228228
sql_query: &str,
229+
cache_mode: &str,
229230
) -> Result<(), CubeError> {
230231
let span_id = Some(Arc::new(SpanId::new(
231232
Uuid::new_v4().to_string(),
@@ -427,6 +428,8 @@ fn exec_sql(mut cx: FunctionContext) -> JsResult<JsValue> {
427428
Err(_) => None,
428429
};
429430

431+
let cache_mode = cx.argument::<JsString>(4)?.value(&mut cx);
432+
430433
let js_stream_on_fn = Arc::new(
431434
node_stream
432435
.get::<JsFunction, _, _>(&mut cx, "on")?
@@ -474,6 +477,7 @@ fn exec_sql(mut cx: FunctionContext) -> JsResult<JsValue> {
474477
channel.clone(),
475478
stream_methods,
476479
&sql_query,
480+
&cache_mode,
477481
)
478482
.await;
479483

0 commit comments

Comments
 (0)