Closed timongll closed 7 months ago
I checked it with a simple React app:
import { useEffect, useState } from 'react'
import { createClient } from '@clickhouse/client-web'
export function App() {
const client = createClient({
host: 'https://...aws.clickhouse.cloud:8443',
password: '...'
})
const [rows, setRows] = useState<string>()
useEffect(() => {
async function ping() {
console.log('ClickHouse ping')
const result = await client.ping()
if (!result.success) {
console.error(result.error)
} else {
console.log('ClickHouse pong!')
}
}
async function query() {
const rs = await client.query({
query: 'SELECT 42 AS count',
format: 'JSONEachRow',
})
return rs.text()
}
ping().then(() => query().then(setRows))
}, [setRows])
return <span>Result: {rows}</span>
}
export default App
How does your URL
look like? How is your ClickHouse deployed?
thanks i think it kind of worked using clickhouse/client
i am now querying a table but getting this error:
i am using a readonly user
"Cannot modify 'enable_http_compression' setting in readonly mode. "
const row = await client.query({
query,
});
how do i modify this query to only read and not modify
If you are using Node.js, then it is @clickhouse/client
, indeed (see the docs).
Regarding a read-only user, should work like this:
const client = createClient({
compression: {
response: false, // cannot enable HTTP compression for a read-only user
},
})
I just realized that it is not pointed out in the docs as it seems, nor does it have an example. Will add.
@timongll, I added read-only user examples. The output should be something like this:
Created user clickhouse_js_examples_readonly_user_6a9549fb1b984e4880965834f57f1e35 with restricted access to the system database
------------------------------------------------------------------------
[Expected error] Readonly user cannot insert the data into the table. Cause:
ClickHouseError: clickhouse_js_examples_readonly_user_6a9549fb1b984e4880965834f57f1e35: Not enough privileges. To execute this query, it's necessary to have the grant INSERT(id, name) ON default.clickhouse_js_examples_readonly_user_test_data.
at parseError (/home/serge/work/clickhouse-js/examples/node_modules/packages/client-common/src/error/parse_error.ts:29:12)
at ClientRequest.onResponse (/home/serge/work/clickhouse-js/examples/node_modules/packages/client-node/src/connection/node_base_connection.ts:155:28)
at processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: '497',
type: 'ACCESS_DENIED'
}
------------------------------------------------------------------------
[Expected error] Cannot query system.users cause it was not granted. Cause:
ClickHouseError: clickhouse_js_examples_readonly_user_6a9549fb1b984e4880965834f57f1e35: Not enough privileges. To execute this query, it's necessary to have the grant SHOW USERS ON *.*.
at parseError (/home/serge/work/clickhouse-js/examples/node_modules/packages/client-common/src/error/parse_error.ts:29:12)
at ClientRequest.onResponse (/home/serge/work/clickhouse-js/examples/node_modules/packages/client-node/src/connection/node_base_connection.ts:155:28)
at processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: '497',
type: 'ACCESS_DENIED'
}
------------------------------------------------------------------------
Select result: [ { id: '12', name: 'foo' }, { id: '42', name: 'bar' } ]
------------------------------------------------------------------------
[Expected error] Cannot use compression with a read-only user. Cause:
ClickHouseError: Cannot modify 'enable_http_compression' setting in readonly mode.
at parseError (/home/serge/work/clickhouse-js/examples/node_modules/packages/client-common/src/error/parse_error.ts:29:12)
at ClientRequest.onResponse (/home/serge/work/clickhouse-js/examples/node_modules/packages/client-node/src/connection/node_base_connection.ts:155:28)
at processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: '164',
type: 'READONLY'
}
------------------------------------------------------------------------
All done!
Hope this helps.
@timongll, closing this for now. If you have further questions, feel free to re-open or just DM me in the community Slack.
I am attempting to use clickhouse/client-web
i am sure my username/password and host are correct because i can login through curl and clickhouse-client. But when i try to make a simple query i get the error shown in the image