Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

GORM clickhouse driver

License

MIT, MIT licenses found

Licenses found

MIT
LICENCE
MIT
License
NotificationsYou must be signed in to change notification settings

go-gorm/clickhouse

 
 

Repository files navigation

Clickhouse support for GORM

test status

Quick Start

You can simply test your connection to your database with the following:

package mainimport ("gorm.io/driver/clickhouse""gorm.io/gorm")typeUserstruct {NamestringAgeint}funcmain() {dsn:="clickhouse://gorm:gorm@localhost:9942/gorm?dial_timeout=10s&read_timeout=20s"db,err:=gorm.Open(clickhouse.Open(dsn),&gorm.Config{})iferr!=nil {panic("failed to connect database")}// Auto Migratedb.AutoMigrate(&User{})// Set table optionsdb.Set("gorm:table_options","ENGINE=Distributed(cluster, default, hits)").AutoMigrate(&User{})// Set table cluster optionsdb.Set("gorm:table_cluster_options","on cluster default").AutoMigrate(&User{})// Insertdb.Create(&User{Name:"Angeliz",Age:18})// Selectdb.Find(&User{},"name = ?","Angeliz")// Batch Insertuser1:=User{Age:12,Name:"Bruce Lee"}user2:=User{Age:13,Name:"Feynman"}user3:=User{Age:14,Name:"Angeliz"}varusers= []User{user1,user2,user3}db.Create(&users)// ...}

Advanced Configuration

package mainimport (  std_ck"github.com/ClickHouse/clickhouse-go/v2""gorm.io/driver/clickhouse""gorm.io/gorm")sqlDB,err:=std_ck.OpenDB(&std_ck.Options{Addr: []string{"127.0.0.1:9999"},Auth: std_ck.Auth{Database:"default",Username:"default",Password:"",},TLS:&tls.Config{InsecureSkipVerify:true,},Settings: std_ck.Settings{"max_execution_time":60,},DialTimeout:5*time.Second,Compression:&std_ck.Compression{std_ck.CompressionLZ4,},Debug:true,})funcmain() {db,err:= gorm.Open(clickhouse.New(click.Config{Conn:sqlDB,// initialize with existing database conn  })}
package mainimport ("gorm.io/driver/clickhouse""gorm.io/gorm")// refer to https://github.com/ClickHouse/clickhouse-govardsn="clickhouse://username:password@host1:9000,host2:9000/database?dial_timeout=200ms&max_execution_time=60"funcmain() {db,err:=gorm.Open(clickhouse.New(click.Config{DSN:dsn,Conn:conn,// initialize with existing database connDisableDatetimePrecision:true,// disable datetime64 precision, not supported before clickhouse 20.4DontSupportRenameColumn:true,// rename column not supported before clickhouse 20.4DontSupportEmptyDefaultValue:false,// do not consider empty strings as valid default valuesSkipInitializeWithVersion:false,// smart configure based on used versionDefaultGranularity:3,// 1 granule = 8192 rowsDefaultCompression:"LZ4",// default compression algorithm. LZ4 is losslessDefaultIndexType:"minmax",// index stores extremes of the expressionDefaultTableEngineOpts:"ENGINE=MergeTree() ORDER BY tuple()",  }),&gorm.Config{})}

Checkouthttps://gorm.io for details.

About

GORM clickhouse driver

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENCE
MIT
License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go100.0%

[8]ページ先頭

©2009-2025 Movatter.jp