clickhouse-go icon indicating copy to clipboard operation
clickhouse-go copied to clipboard

Allow use HTTP protocol with default API interface

Open jkaflik opened this issue 1 year ago • 2 comments

Currently, it's not possible to use HTTP protocol with default "API" interface. This means HTTP support will be marked as non-experimental.

jkaflik avatar Dec 15 '23 19:12 jkaflik

Hello, I can provide solution with another implementation of Conn interface. I'd like to create clickhouseHttp struct that has methods and fields identical to default clickhouse structure.

So in suggested implementation we will have such structure with provided by Conn interface methods:

type clickhouseHttp struct {
	opt    *Options
	idle   chan *httpConnect
	open   chan struct{}
	exit   chan struct{}
	connID int64
}

Also in this solution we will modify Open func in such way:

switch o.Protocol {
case HTTP:
   conn := &clickhouseHttp{...}
   return conn, nil
case Native:
   conn := &clickhouse{...}
   go conn.startAutoCloseIdleConnections()
   return conn, nil
default:
   return nil, fmt.Errorf("clickhouse: invalid protocol")
}

But one moment is not clear for me, implementation of method ServerVersion will look like

func (ch *clickhouseHttp) ServerVersion() (*driver.ServerVersion, error) {
	var (
		ctx, cancel = context.WithTimeout(context.Background(), ch.opt.DialTimeout)
		conn, err   = ch.acquire(ctx)
	)
	defer cancel()
         ...

	version, err := conn.readVersion(ctx)
	...

	return &driver.ServerVersion{
		Version:  version,
		Timezone: conn.location,
	}, nil
}

It is possible solution? Or it will be better to inject ServerVersion inside httpConnect struct

If such solution looks good, I'd like to work on this issue.

loikx avatar Jan 05 '24 16:01 loikx

@loikx feel free to work on it and submit PR. Thanks!

jkaflik avatar Jan 09 '24 08:01 jkaflik