You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
High performance Swift [ClickHouse](https://clickhouse.tech) client based on [SwiftNIO 2](https://github.com/apple/swift-nio). It is inspired by the [ClickHouse source code](https://github.com/ClickHouse/ClickHouse/tree/master/src/Client) (C++), but written in pure Swift.
6
6
@@ -31,7 +31,7 @@ This client provides raw query capabilities. Connection pooling or relational ab
31
31
$ swift build
32
32
```
33
33
34
-
## Usage
34
+
## Usage
35
35
36
36
1. Connect to a ClickHouseServer. The client requires a `eventLoop` which is usually provided by frameworks which use SwiftNIO. We also use `wait()` for simplicity, but it is discouraged for production code.
37
37
@@ -40,13 +40,13 @@ import NIO
40
40
importClickHouseNIO
41
41
42
42
let config =tryClickHouseConfiguration(
43
-
hostname: "localhost",
44
-
port: 9000,
45
-
user: "default",
46
-
password: "admin",
43
+
hostname: "localhost",
44
+
port: 9000,
45
+
user: "default",
46
+
password: "admin",
47
47
database: "default")
48
-
49
-
let eventLoopGroup =MultiThreadedEventLoopGroup(numberOfThreads: 1)
48
+
49
+
let eventLoopGroup =MultiThreadedEventLoopGroup(numberOfThreads: 1)
50
50
let connection =try ClickHouseConnection.connect(configuration: config, on: eventLoopGroup.next()).wait()
try! conn.connection.query(sql: "SELECT * FROM test").map { res in
@@ -104,10 +104,10 @@ For TLS encrypted connections to the ClickHouse server, a `tlsConfiguration` att
104
104
let tls = TLSConfiguration.forClient(certificateVerification: .none)
105
105
106
106
let config =tryClickHouseConfiguration(
107
-
hostname: "localhost",
108
-
port: 9440,
109
-
user: "default",
110
-
password: "admin",
107
+
hostname: "localhost",
108
+
port: 9440,
109
+
user: "default",
110
+
password: "admin",
111
111
database: "default",
112
112
tlsConfiguration: tls)
113
113
```
@@ -118,7 +118,7 @@ Because networks unreliable by nature, ClickHouseNIO uses different timeouts to
118
118
```swift
119
119
120
120
let config =tryClickHouseConfiguration(
121
-
hostname: "localhost",
121
+
hostname: "localhost",
122
122
...,
123
123
connectTimeout: .seconds(10),
124
124
readTimeout: .seconds(90),
@@ -127,9 +127,9 @@ let config = try ClickHouseConfiguration(
127
127
```
128
128
129
129
All timeouts will close the connection. Different timeouts trigger different exceptions:
130
-
-`connectTimeout` will throw `NIO.ChannelError.connectTimeout(TimeAmount)` if the connection to the ClickHouse server cannot be establised after this period of time.
131
-
-`readTimeout`: If a query is running, and the ClickHouseNIO client does not receive any network package, the conncection is closed and throws `ClickHouseError.readTimeout`. This can happen, if the network connection is interrupted while waiting for a response. Usually, even while waiting for a query result, packages are exchanged very frequently.
132
-
-`queryTimeout` is the total time after a query will be terminated and the connection is closed. Because ClickHouseNIO is also capable of queueing queries, this includes the time in the queue as well. On a very busy server, a long waiting time starts to close connections. If a connection is closed, all queries in the queue will return a failed future with the exception `ClickHouseError.queryTimeout`.
130
+
-`connectTimeout` will throw `NIO.ChannelError.connectTimeout(TimeAmount)` if the connection to the ClickHouse server cannot be established after this period of time.
131
+
-`readTimeout`: If a query is running, and the ClickHouseNIO client does not receive any network package, the connection is closed and throws `ClickHouseError.readTimeout`. This can happen, if the network connection is interrupted while waiting for a response. Usually, even while waiting for a query result, packages are exchanged very frequently.
132
+
-`queryTimeout` is the total time after a query will be terminated and the connection is closed. Because ClickHouseNIO is also capable of queueing queries, this includes the time in the queue as well. On a very busy server, a long waiting time starts to close connections. If a connection is closed, all queries in the queue will return a failed future with the exception `ClickHouseError.queryTimeout`.
133
133
134
134
Timeouts can also be specified for a single query with `connection.command(sql: sql, timeout: .seconds(30))`, but keep in mind that this also includes queue time.
0 commit comments