-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 80e4f5b
Showing
16 changed files
with
998 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
/lib | ||
*.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
src | ||
tsconfig.json | ||
*.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 bytadaniel | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# clickhouse-ts by @bytadaniel | ||
#### Select, insert in-memory batches safely and enjoy Clickhouse! | ||
|
||
### Hello from [LookFor.sale](https://lookforsale.ru) developer which produces WB Analytics! | ||
![Backers on Open Collective](https://lookforsale.ru/wp-content/uploads/2021/06/lfsw.jpg) | ||
|
||
## TS client for clickhouse database with using in-memory caching rows for bulk insertion | ||
|
||
### 💙 Typescript | ||
This package is written in TypeScript because Node.js typing development is already an industry standard. | ||
### 🖐 Bulk insert | ||
It has been empirically verified that in-memory collecting rows is the most efficient and consistent way to insert into Clickhouse. To work with built-in caching, you just need to call the useCaching() method | ||
### 💪 Transparent and Stability | ||
clickhouse-ts doesn't use a lot of abstractions and dependencies, so it's fast and stable. | ||
### 🏗 Ready for production | ||
The Lookforsale team has been using clickhouse-ts effectively for over a year under extreme loads! | ||
### 👍 Batch validation | ||
Double checking data for anomalies during in-memory caching and when inserting a finished batch. | ||
### ✨ Flexibility | ||
Flexible configuration of the Clickhouse client instance and support for all features provided by Clickhouse developers. | ||
### 🌈 Free for use | ||
The package has a public license and is available for download to any developer! | ||
### 🔐 Security | ||
SQL Injection Protection with sqlstring | ||
|
||
|
||
## Documentation | ||
|
||
```js | ||
import { Clickhouse } from 'clickhouse-ts' | ||
import fs from 'fs' | ||
|
||
|
||
const clickhouseInstance = new Clickhouse( | ||
{ | ||
url: 'url', | ||
port: 8443, | ||
user: 'user', | ||
password: 'password', | ||
database: 'database', | ||
ca: fs.readFileSync('cert.crt') | ||
}, | ||
{ | ||
debug: { | ||
mode: true, | ||
/* List of providers to exclude from logging */ | ||
exclude: [...providers] | ||
}, | ||
cache: { | ||
/* after this time chunk will be completed */ | ||
chunkTTLSeconds: 3600, | ||
/* interval of checking chunks */ | ||
chunkResolverIntervalSeconds: 180, | ||
/* count of rows in one chunk */ | ||
chunkSizeLimit: 10_000, | ||
/* 'events': on completed chunk emits event 'chunk'. You can save rows as you want */ | ||
chunkResolveType: 'events' | ||
}, | ||
defaultResponseFormat: 'JSON', | ||
clickhouseOptions: { | ||
/* https://clickhouse.tech/docs/en/operations/settings/settings/ */ | ||
send_progress_in_http_headers: '1' | ||
} | ||
} | ||
) | ||
|
||
clickhouseInstance.useCaching() | ||
|
||
clickhouseInstance.onChunk((chunkId, table, rows) => { | ||
// handle insertion | ||
}) | ||
``` | ||
|
||
## Cache | ||
```js | ||
const response = clickhouseInstance.cache( | ||
'table_strings', | ||
[{ date: '2021-01-01', string: 'str1' }], | ||
{ | ||
responseFormat: 'CSVWithNames' // or other format | ||
// other query options | ||
} | ||
) | ||
``` | ||
|
||
## Insert | ||
```js | ||
const response = await clickhouseInstance.insert( | ||
'table_strings', | ||
[{ date: '2021-01-01', string: 'str1' }], | ||
{ | ||
responseFormat: 'CSVWithNames' // or other format | ||
// other query options | ||
} | ||
) | ||
``` | ||
|
||
## Query | ||
|
||
```js | ||
await clickhouseInstance.query<{ t: string }>('WITH now() as t SELECT t', { | ||
responseFormat: 'TSV', | ||
// ...other query options | ||
}) | ||
|
||
await clickhouseInstance.query(` | ||
CREATE TABLE strings ( | ||
date DateTime('UTC'), | ||
string String | ||
) Engine = ReplacingMergeTree() | ||
PARTITION BY toMonday(date) | ||
ORDER BY (date, string) | ||
`) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { Clickhouse } from "./src/clickhouse/Clickhouse"; | ||
export { Clickhouse } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"name": "clickhouse-ts", | ||
"author": "@daniel_byta Daniel Byta", | ||
"main": "lib/index.js", | ||
"files": [ | ||
"lib/**/*" | ||
], | ||
"version": "1.6.1", | ||
"license": "ISC", | ||
"description": "Clickhouse queries with bulk insert and TypeScript!", | ||
"keywords": [ | ||
"clickhouse", | ||
"bulk", | ||
"ts", | ||
"bulk insert", | ||
"clickhouse-client", | ||
"clickhouse-ts", | ||
"client", | ||
"clickhouse-client", | ||
"caching", | ||
"database" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/bytadaniel/clickhouse-ts.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/bytadaniel/clickhouse-ts/issues" | ||
}, | ||
"homepage": "https://github.com/bytadaniel/clickhouse-ts#readme", | ||
"scripts": { | ||
"build": "rm -rf lib && tsc" | ||
}, | ||
"dependencies": { | ||
"axios": "^0.21.4", | ||
"dayjs": "^1.10.5", | ||
"lodash": "^4.17.21", | ||
"sqlstring": "^2.3.2" | ||
}, | ||
"devDependencies": { | ||
"@types/lodash": "^4.14.181", | ||
"@types/node": "^15.14.9", | ||
"@types/sqlstring": "^2.3.0", | ||
"ts-node": "^10.0.0", | ||
"typescript": "^4.3.4" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
Oops, something went wrong.