fossabot / adonis-clickhouse

clickhouse-client wrapper for AdonisJS v6

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ClickHouse for AdonisJS v6

A third-party wrapper for `@clickhouse/client` in AdonisJS v6.

Caution

This package is not compatible with AdonisJS v5.

Copied a lot from Inspired a lot by @adonijs/redis.

Installation

FOSSA Status

npm install --save adonis-clickhouse
node ace configure adonis-clickhouse

Configuration

You can change it in config/clickhouse.ts, it's all same with createClient Configuration. here is the details: https://clickhouse.com/docs/en/integrations/language-clients/javascript#configuration

Environment Variables

Variable Description Default Value
CLICKHOUSE_DB Database Name default
CLICKHOUSE_USER User default
CLICKHOUSE_PASSWORD Password empty string ''
CLICKHOUSE_HOST Clickhouse connect url http://localhost:8123
CLICKHOUSE_REQUEST_TIMEOUT The request timeout in milliseconds. 30000(30s)
CLICKHOUSE_COMPRESSION_REQUEST Enables compression on the client request body false
CLICKHOUSE_COMPRESSION_RESPONSE Instructs ClickHouse server to respond with compressed response body. true

How to import

As it is a container service, you can init it by

await app.container.make('clickhouse')

or

import clickhouse from 'adonis-clickhouse/services/main'

The way same as @adonisjs/redis.

Query

The imported clickhouse actully is a instance of @clickhouse/client Client, hence those codes are equal:

An example of adonis-clickhouse

import clickhouse from 'adonis-clickhouse/services/main'
await clickhouse.query({
    /* QueryParams */
})

Equaled offical library example

import { createClient } from '@clickhouse/client'
const client = createClient({
  /* configuration */
})
await client.query({
    /* QueryParams */
})

Multi Database Instances

You can config the multi databases and use manager to connect it.

import { manager } from 'adonis-clickhouse/services/main'
// Change main to the name you defined.
const client = manager.connect('main')
await client.query({
    /* QueryParams */
})

Documentation

See Offical ClickHouse JS Library

Lisence

the MIT

License

FOSSA Status

About

clickhouse-client wrapper for AdonisJS v6

License:MIT License


Languages

Language:TypeScript 100.0%