Skip to content

Commit

Permalink
style: use isNode flag
Browse files Browse the repository at this point in the history
  • Loading branch information
wrn14897 committed Jan 9, 2025
1 parent 91a31fd commit 0a6714f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 4 additions & 7 deletions packages/api/src/common/clickhouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import {
ResponseJSON,
} from '@clickhouse/client-common';

import { client as internalClickhouseClient } from '@/clickhouse';
import { SQLInterval } from '@/common/sqlTypes';
import { hashCode } from '@/common/utils';
import { timeBucketByGranularity } from '@/common/utils';
import { isNode, timeBucketByGranularity } from '@/common/utils';
import * as config from '@/config';

export const PROXY_CLICKHOUSE_HOST = '/api/clickhouse-proxy';
Expand Down Expand Up @@ -357,7 +356,6 @@ export const sendQuery = async <T extends DataFormat>({
clickhouse_settings,
connectionId,
queryId,
useNativeClient,
}: {
query: string;
format?: string;
Expand All @@ -366,11 +364,10 @@ export const sendQuery = async <T extends DataFormat>({
clickhouse_settings?: Record<string, any>;
connectionId: string;
queryId?: string;
useNativeClient?: boolean;
}) => {
// TODO: switch to internal client in CI for now
if (useNativeClient || config.IS_CI) {
return internalClickhouseClient.query({
if (isNode) {
const _clickhouse = await import('@/clickhouse');
return _clickhouse.client.query({
query,
query_params,
abort_signal,
Expand Down
8 changes: 8 additions & 0 deletions packages/api/src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import { add } from 'date-fns';

import type { SQLInterval } from '@/common/sqlTypes';

export const isBrowser: boolean =
typeof window !== 'undefined' && typeof window.document !== 'undefined';

export const isNode: boolean =
typeof process !== 'undefined' &&
process.versions != null &&
process.versions.node != null;

// If a user specifies a timestampValueExpression with multiple columns,
// this will return the first one. We'll want to refine this over time
export function getFirstTimestampValueExpression(valueExpression: string) {
Expand Down

0 comments on commit 0a6714f

Please sign in to comment.