Documentation
¶
Overview ¶
Package ch implements Datastore client.
Index ¶
- Constants
- Variables
- func CompressionStrings() []string
- func IsErr(err error, codes ...proto.Error) bool
- func IsException(err error) bool
- func Parameters(m map[string]any) []proto.Parameter
- type Client
- func Connect(ctx context.Context, conn net.Conn, opt Options) (*Client, error)
- func ConnectWithBuffer(ctx context.Context, conn net.Conn, opt Options, buf *proto.Buffer) (*Client, error)
- func Dial(ctx context.Context, opt Options) (c *Client, err error)
- func DialWithBuffer(ctx context.Context, opt Options, buf *proto.Buffer) (c *Client, err error)
- type Compression
- type CompressionLevel
- type CorruptedDataErr
- type Dialer
- type Exception
- type Log
- type Options
- type ProfileEvent
- type ProfileEventType
- type Query
- type Server
- type ServerConn
- type ServerOptions
- type Setting
Constants ¶
const ( DefaultDatabase = "default" DefaultUser = "default" DefaultHost = "127.0.0.1" DefaultPort = 9000 DefaultDialTimeout = 1 * time.Second DefaultHandshakeTimeout = 300 * time.Second DefaultReadTimeout = 3 * time.Second )
Defaults for connection.
const NoTimeout = time.Duration(-1)
NoTimeout is a value for Options.ReadTimeout that disables timeout.
Variables ¶
var ErrClosed = errors.New("client is closed")
ErrClosed means that client was already closed.
Functions ¶
func CompressionStrings ¶
func CompressionStrings() []string
CompressionStrings returns a slice of all String values of the enum
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements Datastore binary protocol client on top of single TCP connection.
func Connect ¶
Connect performs handshake with Datastore server and initializes application level connection.
func ConnectWithBuffer ¶
func ConnectWithBuffer(ctx context.Context, conn net.Conn, opt Options, buf *proto.Buffer) (*Client, error)
ConnectWithBuffer performs handshake with Datastore server and initializes application level connection using the provided buffer.
func Dial ¶
Dial dials requested address and establishes TCP connection to Datastore server, performing handshake.
func DialWithBuffer ¶
DialWithBuffer dials requested address and establishes TCP connection to Datastore server, performing handshake using the provided buffer.
func (*Client) Close ¶
Close closes underlying connection and frees all resources, rendering Client to unusable state.
func (*Client) ServerInfo ¶
func (c *Client) ServerInfo() proto.ServerHello
ServerInfo returns server information.
type Compression ¶
type Compression byte
Compression setting.
Trade bandwidth for CPU.
const ( // CompressionDisabled disables compression. Lowest CPU overhead. CompressionDisabled Compression = iota // CompressionLZ4 enables LZ4 compression for data. Medium CPU overhead. CompressionLZ4 // CompressionZSTD enables ZStandard compression. High CPU overhead. CompressionZSTD // CompressionNone uses no compression but data has checksums. CompressionNone // CompressionLZ4HC enables LZ4HC compression for data. High CPU overhead. CompressionLZ4HC )
func CompressionString ¶
func CompressionString(s string) (Compression, error)
CompressionString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func CompressionValues ¶
func CompressionValues() []Compression
CompressionValues returns all values of the enum
func (Compression) IsACompression ¶
func (i Compression) IsACompression() bool
IsACompression returns "true" if the value is listed in the enum definition. "false" otherwise
func (Compression) String ¶
func (i Compression) String() string
type CompressionLevel ¶
type CompressionLevel uint32
CompressionLevel setting. A level == 0 is invalid and resolves to the default.
Supported by: LZ4HC.
type CorruptedDataErr ¶
CorruptedDataErr means that provided hash mismatch with calculated.
func (*CorruptedDataErr) Error ¶
func (c *CorruptedDataErr) Error() string
type Dialer ¶
type Dialer interface {
DialContext(ctx context.Context, network, address string) (net.Conn, error)
}
A Dialer dials using a context.
type Exception ¶
type Exception struct {
Code proto.Error
Name string
Message string
Stack string
Next []Exception // non-nil only for top exception
}
Exception is server-side error.
func AsException ¶
AsException finds first *Exception in err chain.
type Options ¶
type Options struct {
Logger *zap.Logger // defaults to Nop.
Address string // 127.0.0.1:9000
Database string // "default"
User string // "default"
Password string // blank string by default
QuotaKey string // blank string by default
Compression Compression // disabled by default
CompressionLevel CompressionLevel // compression algorithm specific default
ClientName string // blank string by default
Settings []Setting // none by default
// ReadTimeout is a timeout for reading a single packet from the server.
//
// Defaults to 3s. No timeout if negative (you can use NoTimeout const).
ReadTimeout time.Duration
Dialer Dialer // defaults to net.Dialer
DialTimeout time.Duration // defaults to 1s
TLS *tls.Config // no TLS is used by default
ProtocolVersion int // force protocol version, optional
HandshakeTimeout time.Duration // longer lasting handshake is a case for Datastore cloud idle instances, defaults to 5m
// Additional OpenTelemetry instrumentation that will capture query body
// and other parameters.
//
// Note: OpenTelemetry context propagation works without this option too.
OpenTelemetryInstrumentation bool
TracerProvider trace.TracerProvider
MeterProvider metric.MeterProvider
// SSH authentication.
SSHSigner cryptossh.Signer
// contains filtered or unexported fields
}
Options for Client. Zero value is valid.
type ProfileEvent ¶
type ProfileEvent = proto.ProfileEvent
type ProfileEventType ¶
type ProfileEventType = proto.ProfileEventType
type Query ¶
type Query struct {
// Body of query, like "SELECT 1".
Body string
// QueryID is ID of query, defaults to new UUIDv4.
QueryID string
// QuotaKey of query, optional.
QuotaKey string
// Input columns for INSERT operations.
Input proto.Input
// OnInput is called to allow ingesting more data to Input.
//
// The io.EOF reports that no more input should be ingested.
//
// Optional, single block is ingested from Input if not provided,
// but query will fail if Input is set but has zero rows.
OnInput func(ctx context.Context) error
// Result columns for SELECT operations.
Result proto.Result
// OnResult is called when Result is filled with result block.
//
// Optional, but query will fail of more than one block is received
// and no OnResult is provided.
OnResult func(ctx context.Context, block proto.Block) error
// OnProgress is optional progress handler. The progress value contain
// difference, so progress should be accumulated if needed.
OnProgress func(ctx context.Context, p proto.Progress) error
// OnProfile is optional handler for profiling data.
OnProfile func(ctx context.Context, p proto.Profile) error
// OnProfileEvent is optional handler for profiling event stream data.
//
// Deprecated: use OnProfileEvents instead. This option will be removed in
// next major release.
OnProfileEvent func(ctx context.Context, e ProfileEvent) error
// OnProfileEvents is same as OnProfileEvent but is called on each event batch.
OnProfileEvents func(ctx context.Context, e []ProfileEvent) error
// OnLog is optional handler for server log entry.
//
// Deprecated: use OnLogs instead. This option will be removed in
// next major release.
OnLog func(ctx context.Context, l Log) error
// OnLogs is optional handler for server log events.
OnLogs func(ctx context.Context, l []Log) error
// Settings are optional query-scoped settings. Can override client settings.
Settings []Setting
// EXPERIMENTAL: parameters for query.
Parameters []proto.Parameter
// Secret is optional inter-server per-cluster secret for Distributed queries.
//
// See https://docs.hanzo.ai/datastore
Secret string
// InitialUser is optional initial user for Distributed queries.
InitialUser string
// ExternalData is optional data for server to load.
//
// https://docs.hanzo.ai/datastore
ExternalData []proto.InputColumn
// ExternalTable name. Defaults to _data.
ExternalTable string
// Logger for query, optional, defaults to client logger with `query_id` field.
Logger *zap.Logger
}
Query to Datastore.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is basic Datastore server.
type ServerConn ¶
type ServerConn struct {
// contains filtered or unexported fields
}
ServerConn wraps Server connection.
type ServerOptions ¶
ServerOptions wraps possible Server configuration.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package compress implements compression support.
|
Package compress implements compression support. |
|
internal
|
|
|
version
Package version resolves current module version.
|
Package version resolves current module version. |
|
Package chpool is a connection pool for ch.
|
Package chpool is a connection pool for ch. |
|
Package proto implements Datastore wire protocol.
|
Package proto implements Datastore wire protocol. |
|
Package tracing provide OpenTelemetry instrumentation for go-faster/ch.
|
Package tracing provide OpenTelemetry instrumentation for go-faster/ch. |