Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readme advanced config example is wrong #79

Open
SpikeWong opened this issue Feb 2, 2023 · 1 comment
Open

Readme advanced config example is wrong #79

SpikeWong opened this issue Feb 2, 2023 · 1 comment
Assignees

Comments

@SpikeWong
Copy link

github.com/ClickHouse/clickhouse-go/v2 has not been imported

package main

import (
  "gorm.io/driver/clickhouse"
  "gorm.io/gorm"
)

// should be github.com/ClickHouse/clickhouse-go/v2
sqlDB, err := clickhouse.OpenDB(&clickhouse.Options{
	Addr: []string{"127.0.0.1:9999"},
	Auth: clickhouse.Auth{
		Database: "default",
		Username: "default",
		Password: "",
	},
	TLS: &tls.Config{
		InsecureSkipVerify: true,
	},
	Settings: clickhouse.Settings{
		"max_execution_time": 60,
	},
	DialTimeout: 5 * time.Second,
	Compression: &clickhouse.Compression{
		clickhouse.CompressionLZ4,
	},
	Debug: true,
})

func main() {
  db, err := gorm.Open(clickhouse.New(click.Config{
    Conn: sqlDB, // initialize with existing database conn
  })
}
@st3rv04ka
Copy link

Fixed version:

package main

import (
  "time"
  "crypto/tls"
  "github.com/ClickHouse/clickhouse-go/v2"
  click "gorm.io/driver/clickhouse"
  "gorm.io/gorm"
)

func main() {
	sql := clickhouse.OpenDB(&clickhouse.Options{
	Addr: []string{"127.0.0.1:9440"}, // secure port
	Auth: clickhouse.Auth{
		Database: "database",
		Username: "user",
		Password: "password",
	},
	TLS: &tls.Config{
		InsecureSkipVerify: true,
	},
	Settings: clickhouse.Settings{
		"max_execution_time": 60,
	},
	DialTimeout: 5 * time.Second,
	Debug: true,
	})

	db, err = gorm.Open(click.New(click.Config{Conn: sql}))
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants