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

Insertion of string enum array #61

Open
iam047801 opened this issue Feb 27, 2023 · 0 comments
Open

Insertion of string enum array #61

iam047801 opened this issue Feb 27, 2023 · 0 comments

Comments

@iam047801
Copy link

I expect no errors while executing the code below, but instead I get panic with interface conversion: interface {} is []main.Address, not []string error on go-clickhouse/ch/chschema/column.go:115.

package main

import (
	"context"
	"fmt"
	"reflect"

	"github.com/uptrace/go-clickhouse/ch"
)

type Address string

type ProblemStruct struct {
	Addresses []Address `ch:"type:Array(String)"`
}

func main() {
	var v = ProblemStruct{
		Addresses: []Address{"1", "2"},
	}

	dsnCH := "clickhouse://localhost:9000/default?sslmode=disable"
	chDB := ch.Connect(
		ch.WithDSN(dsnCH), ch.WithAutoCreateDatabase(true), ch.WithPoolSize(16))

	_, err := chDB.NewDropTable().
		Model(new(ProblemStruct)).
		IfExists().
		Exec(context.Background())
	if err != nil {
		panic(err)
	}

	_, err = chDB.NewCreateTable().
		Model(new(ProblemStruct)).
		IfNotExists().
		Engine("ReplacingMergeTree").
		Exec(context.Background())
	if err != nil {
		panic(err)
	}

	_, err = chDB.NewInsert().Model(&v).Exec(context.Background())
	if err != nil {
		panic(err)
	}

	var got ProblemStruct

	err = chDB.NewSelect().Model(&got).Scan(context.Background())
	if err != nil {
		panic(err)
	}

	if !reflect.DeepEqual(v, got) {
		fmt.Printf("expected: %+v", v)
		fmt.Printf("got: %+v", v)
		panic(nil)
	}
}

Version: [email protected]

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

1 participant