-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.go
More file actions
39 lines (33 loc) · 807 Bytes
/
db.go
File metadata and controls
39 lines (33 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"context"
"github.com/ClickHouse/clickhouse-go/v2"
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
)
func Connect() (driver.Conn, error) {
conn, err := clickhouse.Open(&clickhouse.Options{
Addr: []string{"localhost:9000"}, // Menggunakan port TCP native
Auth: clickhouse.Auth{
Database: "iot_analytics",
Username: "admin",
Password: "securepassword123",
},
ClientInfo: clickhouse.ClientInfo{
Products: []struct {
Name string
Version string
}{
{Name: "iot_analytics-app", Version: "0.1"},
},
},
Debug: true, // Aktifkan untuk melihat log query
})
if err != nil {
return nil, err
}
// Ping untuk memastikan koneksi berhasil
if err := conn.Ping(context.Background()); err != nil {
return nil, err
}
return conn, nil
}