Skip to content

Commit 1a19469

Browse files
committed
Clickhouse fixes
1 parent 923bcb6 commit 1a19469

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

dialects/clickhouse/clickhouse.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,15 @@ func (s *clickhouse) DataTypeOf(field *gorm.StructField) string {
4747
var dataValue, sqlType, _, additionalType = gorm.ParseFieldStructForDialect(field, s)
4848

4949
if sqlType == "" {
50-
switch dataValue.Kind() {
50+
typeToCheck := dataValue.Kind()
51+
52+
if dataValue.Kind() == reflect.Slice {
53+
typeToCheck = field.Struct.Type.Elem().Kind()
54+
}
55+
56+
switch typeToCheck {
5157
case reflect.Bool:
52-
sqlType = "Uint8"
58+
sqlType = "UInt8"
5359

5460
case reflect.Int8:
5561
sqlType = "Int8"
@@ -86,6 +92,10 @@ func (s *clickhouse) DataTypeOf(field *gorm.StructField) string {
8692
sqlType = "String"
8793
}
8894
}
95+
96+
if sqlType != "" && dataValue.Kind() == reflect.Slice {
97+
sqlType = "Array(" + sqlType + ")"
98+
}
8999
}
90100

91101
if sqlType == "" {
@@ -130,7 +140,7 @@ func (s clickhouse) ModifyColumn(tableName string, columnName string, typ string
130140
}
131141

132142
func (s clickhouse) CurrentDatabase() (name string) {
133-
s.db.QueryRow("SELECT currentDatabse()").Scan(&name)
143+
s.db.QueryRow("SELECT currentDatabase()").Scan(&name)
134144
return
135145
}
136146

0 commit comments

Comments
 (0)