From 9316dbd8cb28fff11816e00f5e65c4480911fb2c Mon Sep 17 00:00:00 2001 From: slvrtrn Date: Thu, 21 Sep 2023 17:00:26 +0200 Subject: [PATCH] Add session_level_commands example --- examples/session_level_commands.ts | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/session_level_commands.ts diff --git a/examples/session_level_commands.ts b/examples/session_level_commands.ts new file mode 100644 index 00000000..fb1bd0cb --- /dev/null +++ b/examples/session_level_commands.ts @@ -0,0 +1,36 @@ +import { createClient } from '@clickhouse/client' // or '@clickhouse/client-web' +import * as crypto from 'crypto' // required for Node.js only + +void (async () => { + const client = createClient({ + // with session_id defined, SET and other session commands + // will affect all the consecutive queries + session_id: crypto.randomUUID(), + }) + + await client.command({ + query: `SET output_format_json_quote_64bit_integers = 0`, + clickhouse_settings: { wait_end_of_query: 1 }, + }) + + // this query uses output_format_json_quote_64bit_integers = 0 + const rows1 = await client.query({ + query: `SELECT toInt64(42)`, + format: 'JSONEachRow', + }) + console.log(await rows1.json()) + + await client.command({ + query: `SET output_format_json_quote_64bit_integers = 1`, + clickhouse_settings: { wait_end_of_query: 1 }, + }) + + // this query uses output_format_json_quote_64bit_integers = 1 + const rows2 = await client.query({ + query: `SELECT toInt64(144)`, + format: 'JSONEachRow', + }) + console.log(await rows2.json()) + + await client.close() +})()