WIP: Refactor client to support custom connections #163
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Refactor the client to support custom connections.
NB: I haven't implemented connections other than the existing Node.js one yet; the first attempt (browser) is planned as a follow-up. This is just the necessary restructuring before we can make some progress there.
Related issues:
http
#153The code now is a small monorepo, divided into several workspaces
The idea is that we can create new connections (fetch/axios/whatever) as just a new workspace and run CI using all of them one by one (run all tests with node connections, run a subset of tests for the browser, etc).
This also means we will have multiple NPM packages - the base client itself without a connection implementation included (replacing current
@clickhouse/client
) and at least one package per connection (@clickhouse/client-node
,@clickhouse/client-fetch
). The end user will have to install only one, though. This PR does not address the release routine (need to address the imports/paths, adjust GitHub Actions, etc)Once it is released (when at least one new connection is made), the changes for the existing Node.js users should be minimal, just a simple change of import (
createClient
will come from@clickhouse/client-node
instead of@clickhouse/client
).For example, with
@clickhouse/client-node
:See the workspace source for more details.
However, if just
@clickhouse/client
is added as a dependency, it is now possible to implement a custom version of theConnection
interface and pass it with client configuration options.For example:
Where
MyCustomConnection
implementsSee connection.ts for more details.
Currently, we have
stream
andBuffer
as leftover Node.js-specific types in the common module. However, there are polyfills available:Again, as a follow-up, I will investigate what is possible for the browser or, for example, Cloudflare workers since these are the common use cases.
Checklist