Files
zeekay 765c3d0aa1 hanzo-ds/native: de-branded native protocol lib (fork of clickhouse ch-go v0.71.0)
Module path, package names, and identifiers de-branded to native/proto/compress/
pool/tracing. Server wire-protocol strings preserved. Vendored codec surface used
by hanzo-ds/go (proto + compress).
2026-07-10 13:10:07 -07:00

58 lines
913 B
Go

package pool
import (
"context"
"time"
"github.com/jackc/puddle/v2"
"github.com/hanzo-ds/native"
)
// Client is an acquired *native.Client from a Pool.
type Client struct {
res *puddle.Resource[*connResource]
p *Pool
}
// Release returns client to the pool.
func (c *Client) Release() {
if c.res == nil {
return
}
client := c.client()
if client.IsClosed() || time.Since(c.res.CreationTime()) > c.p.options.MaxConnLifetime {
c.res.Destroy()
return
}
c.res.Release()
}
func (c *Client) Do(ctx context.Context, q native.Query) (err error) {
return c.client().Do(ctx, q)
}
func (c *Client) Ping(ctx context.Context) error {
return c.client().Ping(ctx)
}
func (c *Client) Close() error {
var err error
client := c.client()
if !client.IsClosed() {
err = client.Close()
}
c.res.Destroy()
return err
}
func (c *Client) client() *native.Client {
return c.res.Value().client
}