Skip to content

Commit

Permalink
Remove JSON type use from a context use example (#1379)
Browse files Browse the repository at this point in the history
This breaks when run against HEAD ClickHouse version
  • Loading branch information
jkaflik authored Aug 22, 2024
1 parent 9b995de commit 6ce41c3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
23 changes: 10 additions & 13 deletions examples/clickhouse_api/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ package clickhouse_api
import (
"context"
"fmt"
"net"
"time"

"github.com/ClickHouse/clickhouse-go/v2"
clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests"
"github.com/google/uuid"
"net"
"time"
)

func UseContext() error {
Expand Down Expand Up @@ -54,19 +55,15 @@ func UseContext() error {
}
// we can use context to pass settings to a specific API call
ctx := clickhouse.Context(context.Background(), clickhouse.WithSettings(clickhouse.Settings{
"allow_experimental_object_type": "1",
"async_insert": "1",
}))

conn.Exec(ctx, "DROP TABLE IF EXISTS example")

// to create a JSON column we need allow_experimental_object_type=1
if err = conn.Exec(ctx, `
CREATE TABLE example (
Col1 JSON
)
Engine Memory
`); err != nil {
return err
var settingValue bool
if err := conn.QueryRow(ctx, "SELECT getSetting('async_insert')").Scan(&settingValue); err != nil {
return fmt.Errorf("failed to get setting value: %v", err)
}
if !settingValue {
return fmt.Errorf("expected setting value to be true, got false")
}

// queries can be cancelled using the context
Expand Down
20 changes: 9 additions & 11 deletions examples/std/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ package std
import (
"context"
"fmt"
"time"

"github.com/ClickHouse/clickhouse-go/v2"
clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests/std"
"github.com/google/uuid"
"time"
)

func UseContext() error {
Expand All @@ -36,17 +37,14 @@ func UseContext() error {
}
// we can use context to pass settings to a specific API call
ctx := clickhouse.Context(context.Background(), clickhouse.WithSettings(clickhouse.Settings{
"allow_experimental_object_type": "1",
"async_insert": "1",
}))
conn.ExecContext(ctx, "DROP TABLE IF EXISTS example")
// to create a JSON column we need allow_experimental_object_type=1
if _, err = conn.ExecContext(ctx, `
CREATE TABLE example (
Col1 JSON
)
Engine Memory
`); err != nil {
return err
var settingValue bool
if err := conn.QueryRowContext(ctx, "SELECT getSetting('async_insert')").Scan(&settingValue); err != nil {
return fmt.Errorf("failed to get setting value: %v", err)
}
if !settingValue {
return fmt.Errorf("expected setting value to be true, got false")
}

// queries can be cancelled using the context
Expand Down

0 comments on commit 6ce41c3

Please sign in to comment.