Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Refactor client to support custom connections #163

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .build/update_version.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import version from '../src/version'
import version from '../packages/common/src/version'
import packageJson from '../package.json'
import fs from 'fs'
;(async () => {
Expand Down
5 changes: 2 additions & 3 deletions __tests__/integration/abort_request.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AbortController } from 'node-abort-controller'
import type { Row } from '../../src'
import { type ClickHouseClient, type ResponseJSON } from '../../src'
import type { Row } from 'client/src'
import { type ClickHouseClient, type ResponseJSON } from 'client/src'
import { createTestClient, guid, makeObjectStream } from '../utils'
import { createSimpleTable } from './fixtures/simple_table'
import type Stream from 'stream'
Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration/auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ClickHouseClient } from '../../src'
import { type ClickHouseClient } from 'client/src'
import { createTestClient } from '../utils'

describe('authentication', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/integration/clickhouse_settings.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ClickHouseClient, InsertParams } from '../../src'
import { SettingsMap } from '../../src'
import type { ClickHouseClient, InsertParams } from 'client/src'
import { SettingsMap } from 'client/src'
import { createTestClient, guid } from '../utils'
import { createSimpleTable } from './fixtures/simple_table'

Expand Down
6 changes: 3 additions & 3 deletions __tests__/integration/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Logger } from '../../src'
import { type ClickHouseClient } from '../../src'
import type { Logger } from 'client/src'
import { type ClickHouseClient } from 'client/src'
import { createTestClient, retryOnFailure } from '../utils'
import type { RetryOnFailureOptions } from '../utils/retry'
import type { ErrorLogParams, LogParams } from '../../src/logger'
import type { ErrorLogParams, LogParams } from 'client-common/src/logger'

describe('config', () => {
let client: ClickHouseClient
Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration/data_types.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ClickHouseClient } from '../../src'
import type { ClickHouseClient } from 'client/src'
import { createTestClient } from '../utils'
import { v4 } from 'uuid'
import { randomInt } from 'crypto'
Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration/date_time.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createTableWithFields } from './fixtures/table_with_fields'
import type { ClickHouseClient } from '../../src'
import type { ClickHouseClient } from 'client/src'
import { createTestClient } from '../utils'

describe('DateTime', () => {
Expand Down
3 changes: 2 additions & 1 deletion __tests__/integration/error_parsing.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type ClickHouseClient, createClient } from '../../src'
import { createTestClient, getTestDatabaseName } from '../utils'
import type { ClickHouseClient } from 'client/src'
import { createClient } from 'client-node/src'

describe('error', () => {
let client: ClickHouseClient
Expand Down
8 changes: 4 additions & 4 deletions __tests__/integration/exec.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { ExecParams, ResponseJSON } from '../../src'
import { type ClickHouseClient } from '../../src'
import type { ExecParams, ResponseJSON } from 'client/src'
import { type ClickHouseClient } from 'client/src'
import {
createTestClient,
getClickHouseTestEnvironment,
getTestDatabaseName,
guid,
TestEnv,
} from '../utils'
import { getAsText } from '../../src/utils'
import * as uuid from 'uuid'
import type { QueryResult } from '../../src/connection'
import { getAsText } from 'client-common/src/utils'
import type { QueryResult } from 'client-common/src/connection'

describe('exec', () => {
let client: ClickHouseClient
Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration/fixtures/read_only_user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
guid,
TestEnv,
} from '../../utils'
import type { ClickHouseClient } from '../../../src'
import type { ClickHouseClient } from 'client/src'

export async function createReadOnlyUser(client: ClickHouseClient) {
const username = `clickhousejs__read_only_user_${guid()}`
Expand Down
6 changes: 3 additions & 3 deletions __tests__/integration/fixtures/simple_table.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createTable, TestEnv } from '../../utils'
import type { ClickHouseClient } from '../../../src'
import type { MergeTreeSettings } from '../../../src/settings'
import type { ClickHouseClient } from 'client/src'
import type { MergeTreeSettings } from 'client-common/src/settings'

export function createSimpleTable(
client: ClickHouseClient,
Expand Down Expand Up @@ -39,7 +39,7 @@ export function createSimpleTable(
CREATE TABLE ${tableName} ON CLUSTER '{cluster}'
(id UInt64, name String, sku Array(UInt8))
ENGINE ReplicatedMergeTree(
'/clickhouse/{cluster}/tables/{database}/{table}/{shard}',
'/clickhouse/{cluster}/tables/{database}/{table}/{shard}',
'{replica}'
)
ORDER BY (id) ${_settings}
Expand Down
4 changes: 2 additions & 2 deletions __tests__/integration/fixtures/table_with_fields.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createTable, guid, TestEnv } from '../../utils'
import type { ClickHouseClient, ClickHouseSettings } from '../../../src'
import type { ClickHouseClient, ClickHouseSettings } from 'client/src'

export async function createTableWithFields(
client: ClickHouseClient,
Expand Down Expand Up @@ -31,7 +31,7 @@ export async function createTableWithFields(
CREATE TABLE ${tableName} ON CLUSTER '{cluster}'
(id UInt32, ${fields})
ENGINE ReplicatedMergeTree(
'/clickhouse/{cluster}/tables/{database}/{table}/{shard}',
'/clickhouse/{cluster}/tables/{database}/{table}/{shard}',
'{replica}'
)
ORDER BY (id)
Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration/fixtures/test_data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ClickHouseClient } from '../../../src'
import type { ClickHouseClient } from 'client/src'

export const jsonValues = [
{ id: '42', name: 'hello', sku: [0, 1] },
Expand Down
4 changes: 2 additions & 2 deletions __tests__/integration/insert.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ResponseJSON } from '../../src'
import { type ClickHouseClient } from '../../src'
import type { ResponseJSON } from 'client/src'
import { type ClickHouseClient } from 'client/src'
import { createTestClient, guid } from '../utils'
import { createSimpleTable } from './fixtures/simple_table'
import { assertJsonValues, jsonValues } from './fixtures/test_data'
Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration/multiple_clients.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ClickHouseClient } from '../../src'
import type { ClickHouseClient } from 'client/src'
import { createSimpleTable } from './fixtures/simple_table'
import { createTestClient, guid } from '../utils'
import Stream from 'stream'
Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration/ping.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ClickHouseClient } from '../../src'
import { type ClickHouseClient } from 'client/src'
import { createTestClient } from '../utils'

describe('ping', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration/query_log.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ClickHouseClient } from '../../src'
import { type ClickHouseClient } from 'client/src'
import {
createTestClient,
guid,
Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration/read_only_user.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ClickHouseClient } from '../../src'
import type { ClickHouseClient } from 'client/src'
import { createTestClient, getTestDatabaseName, guid } from '../utils'
import { createSimpleTable } from './fixtures/simple_table'
import { createReadOnlyUser } from './fixtures/read_only_user'
Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration/request_compression.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ClickHouseClient, type ResponseJSON } from '../../src'
import { type ClickHouseClient, type ResponseJSON } from 'client/src'
import { createTestClient, guid } from '../utils'
import { createSimpleTable } from './fixtures/simple_table'

Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration/response_compression.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ClickHouseClient } from '../../src'
import { type ClickHouseClient } from 'client/src'
import { createTestClient } from '../utils'

describe('response compression', () => {
Expand Down
6 changes: 3 additions & 3 deletions __tests__/integration/schema_e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ClickHouseClient } from '../../src'
import type { ClickHouseClient } from 'client/src'
import { createTableWithSchema, createTestClient, guid } from '../utils'
import * as ch from '../../src/schema'
import { And, Eq, Or } from '../../src/schema'
import * as ch from 'client/src/schema'
import { And, Eq, Or } from 'client/src/schema'

describe('schema e2e test', () => {
let client: ClickHouseClient
Expand Down
4 changes: 2 additions & 2 deletions __tests__/integration/schema_types.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ClickHouseClient } from '../../src'
import type { ClickHouseClient } from 'client/src'
import { createTableWithSchema, createTestClient, guid } from '../utils'

import * as ch from '../../src/schema'
import * as ch from 'client/src/schema'

describe('schema types', () => {
let client: ClickHouseClient
Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration/select.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type Stream from 'stream'
import { type ClickHouseClient, type ResponseJSON, type Row } from '../../src'
import { type ClickHouseClient, type ResponseJSON, type Row } from 'client/src'
import { createTestClient, guid } from '../utils'
import * as uuid from 'uuid'

Expand Down
4 changes: 2 additions & 2 deletions __tests__/integration/select_query_binding.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { QueryParams } from '../../src'
import { type ClickHouseClient } from '../../src'
import type { QueryParams } from 'client/src'
import { type ClickHouseClient } from 'client/src'
import { createTestClient } from '../utils'

describe('select with query binding', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration/stream_json_formats.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ClickHouseClient } from '../../src'
import { type ClickHouseClient } from 'client/src'
import Stream from 'stream'
import { createTestClient, guid, makeObjectStream } from '../utils'
import { createSimpleTable } from './fixtures/simple_table'
Expand Down
4 changes: 2 additions & 2 deletions __tests__/integration/stream_raw_formats.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createTestClient, guid, makeRawStream } from '../utils'
import type { ClickHouseClient, ClickHouseSettings } from '../../src'
import type { ClickHouseClient, ClickHouseSettings } from 'client/src'
import { createSimpleTable } from './fixtures/simple_table'
import Stream from 'stream'
import { assertJsonValues, jsonValues } from './fixtures/test_data'
import type { RawDataFormat } from '../../src/data_formatter'
import type { RawDataFormat } from 'client-common/src/data_formatter'

describe('stream raw formats', () => {
let client: ClickHouseClient
Expand Down
4 changes: 2 additions & 2 deletions __tests__/integration/streaming_e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Fs from 'fs'
import Path from 'path'
import Stream from 'stream'
import split from 'split2'
import type { Row } from '../../src'
import { type ClickHouseClient } from '../../src'
import type { Row } from 'client/src'
import { type ClickHouseClient } from 'client/src'
import { createTestClient, guid } from '../utils'
import { createSimpleTable } from './fixtures/simple_table'

Expand Down
4 changes: 2 additions & 2 deletions __tests__/integration/watch_stream.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Row } from '../../src'
import { type ClickHouseClient } from '../../src'
import type { Row } from 'client/src'
import { type ClickHouseClient } from 'client/src'
import {
createTable,
createTestClient,
Expand Down
4 changes: 2 additions & 2 deletions __tests__/tls/tls.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ClickHouseClient } from '../../src'
import { createClient } from '../../src'
import type { ClickHouseClient } from 'client/src'
import { createTestClient } from '../utils'
import * as fs from 'fs'
import { createClient } from 'client-node/src'

describe('TLS connection', () => {
let client: ClickHouseClient
Expand Down
6 changes: 3 additions & 3 deletions __tests__/unit/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ClickHouseClientConfigOptions } from '../../src'
import { createClient } from '../../src'
import type { ClickHouseClientConfigOptions } from 'client/src'
import { createClient } from 'client-node/src'

describe('createClient', () => {
it('throws on incorrect "host" config value', () => {
Expand All @@ -9,7 +9,7 @@ describe('createClient', () => {
})

it('should not mutate provided configuration', async () => {
const config: ClickHouseClientConfigOptions = {
const config: Omit<ClickHouseClientConfigOptions, 'connection'> = {
host: 'http://localhost',
}
createClient(config)
Expand Down
35 changes: 0 additions & 35 deletions __tests__/unit/connection.test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions __tests__/unit/encode_values.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Stream from 'stream'
import { encodeValues } from '../../src/client'
import type { DataFormat, InputJSON, InputJSONObjectEachRow } from '../../src'
import { encodeValues } from 'client/src/client'
import type { DataFormat, InputJSON, InputJSONObjectEachRow } from 'client/src'

describe('encodeValues', () => {
const rawFormats = [
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/format_query_params.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatQueryParams } from '../../src/data_formatter'
import { formatQueryParams } from 'client-common/src/data_formatter'

// JS always creates Date object in local timezone,
// so we might need to convert the date to another timezone
Expand Down
4 changes: 2 additions & 2 deletions __tests__/unit/format_query_settings.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { formatQuerySettings } from '../../src/data_formatter'
import { SettingsMap } from '../../src'
import { formatQuerySettings } from 'client-common/src/data_formatter'
import { SettingsMap } from 'client/src'

describe('formatQuerySettings', () => {
it('formats boolean', () => {
Expand Down
8 changes: 6 additions & 2 deletions __tests__/unit/logger.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { ErrorLogParams, Logger, LogParams } from '../../src/logger'
import { LogWriter } from '../../src/logger'
import type {
ErrorLogParams,
Logger,
LogParams,
} from 'client-common/src/logger'
import { LogWriter } from 'client-common/src/logger'

describe('Logger', () => {
type LogLevel = 'debug' | 'info' | 'warn' | 'error'
Expand Down
27 changes: 27 additions & 0 deletions __tests__/unit/node_connection.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { createConnection } from 'client-node/src'
import { NodeHttpConnection } from 'client-node/src/node_http_connection'
import { NodeHttpsConnection } from 'client-node/src/node_https_connection'

describe('Node.js connection', () => {
it('should create HTTP adapter', async () => {
const adapter = createConnection({
url: new URL('http://localhost'),
} as any)
expect(adapter).toBeInstanceOf(NodeHttpConnection)
})

it('should create HTTPS adapter', async () => {
const adapter = createConnection({
url: new URL('https://localhost'),
} as any)
expect(adapter).toBeInstanceOf(NodeHttpsConnection)
})

it('should throw if the supplied protocol is unknown', async () => {
expect(() =>
createConnection({
url: new URL('tcp://localhost'),
} as any)
).toThrowError('Only HTTP(s) adapters are supported')
})
})
Loading