1 Star 0 Fork 0

carlmax_my/console-core-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
clickhouse.go 2.09 KB
一键复制 编辑 原始数据 按行查看 历史
carlmax_my 提交于 2024-12-02 21:32 . init project
package clickhouse
import (
"context"
"fmt"
"os"
"github.com/ClickHouse/clickhouse-go/v2"
)
// public API
func NewClickHouseConn() (clickhouse.Conn, error) {
host := os.Getenv("CLICKHOUSE_HOST")
port := os.Getenv("CLICKHOUSE_PORT")
return clickhouse.Open(&clickhouse.Options{
Addr: []string{fmt.Sprintf("%v:%v", host, port)},
Auth: clickhouse.Auth{
Database: os.Getenv("CLICKHOUSE_DATABASE"),
Username: os.Getenv("CLICKHOUSE_USERNAME"),
Password: os.Getenv("CLICKHOUSE_PASSWORD"),
},
})
}
func GetClientDbTbl() string {
return fmt.Sprintf("%v.%v", os.Getenv("CLICKHOUSE_DATABASE"), os.Getenv("CLICKHOUSE_CLIENT_LOG_TABLE"))
}
func GetSystemDbTbl() string {
return fmt.Sprintf("%v.%v", os.Getenv("CLICKHOUSE_DATABASE"), os.Getenv("CLICKHOUSE_SYSTEM_LOG_TABLE"))
}
func GetSwgReportDbTbl() string {
return fmt.Sprintf("%v.%v", os.Getenv("CLICKHOUSE_DATABASE"), os.Getenv("CLICKHOUSE_SWG_URL_COLLECT_TABLE"))
}
func GetSwgCfsCategoryDbTbl() string {
return fmt.Sprintf("%v.%v", os.Getenv("CLICKHOUSE_DATABASE"), os.Getenv("CLICKHOUSE_CFS_CATEGORY_TABLE"))
}
func GetSwgCfsDomainsDbTbl() string {
return fmt.Sprintf("%v.%v", os.Getenv("CLICKHOUSE_DATABASE"), os.Getenv("CLICKHOUSE_CFS_DOMAINS_TABLE"))
}
func GetSwgAppCtrlAppActivityDbTbl() string {
return fmt.Sprintf("%v.%v", os.Getenv("CLICKHOUSE_DATABASE"), os.Getenv("CLICKHOUSE_APP_CTRL_APP_ACTIVITY_TABLE"))
}
func GetSwgAppCtrlAppInfoDbTbl() string {
return fmt.Sprintf("%v.%v", os.Getenv("CLICKHOUSE_DATABASE"), os.Getenv("CLICKHOUSE_APP_CTRL_APP_INFO_TABLE"))
}
func GetSwgAppCtrlAppActivityInfoDbTbl() string {
return fmt.Sprintf("%v.%v", os.Getenv("CLICKHOUSE_DATABASE"), os.Getenv("CLICKHOUSE_APP_CTRL_APP_ACTIVITY_INFO_TABLE"))
}
func ClickHouseCount(dql string, asName string) (ret uint64, err error) {
conn, err := NewClickHouseConn()
if err != nil {
return 0, err
}
var countResult struct {
LogNum uint64 `ch:"logNum"`
}
// countResult := make([]CountResult, 0)
ctx := context.TODO()
if err = conn.QueryRow(ctx, dql).ScanStruct(&countResult); err != nil {
return 0, err
}
ret = countResult.LogNum
return ret, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/carlmax_my/console-core-go.git
git@gitee.com:carlmax_my/console-core-go.git
carlmax_my
console-core-go
console-core-go
v0.0.14

搜索帮助

0d507c66 1850385 C8b1a773 1850385