Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Batch ¶
type Batch interface {
Abort() error
Append(v ...any) error
AppendStruct(v any) error
Column(int) BatchColumn
// Flush sends the currently buffered rows but keeps the batch usable.
//
// For native protocol this transmits the buffered block to the server and clears the local buffer.
// For HTTP protocol this is currently a no-op.
Flush() error
// Send flushes any buffered rows and finalizes the INSERT.
// After Send() the batch is considered sent and should not be reused.
Send() error
// IsSent reports whether the batch has been finalized via Send(), Abort(), or Close().
IsSent() bool
Rows() int
Columns() []column.Interface
// Close ends the current INSERT and releases resources.
//
// It is safe (and recommended) to call Close via defer immediately after PrepareBatch.
// Close does not guarantee that buffered rows are sent; call Send() to finalize the INSERT.
Close() error
}
Batch represents a prepared INSERT that buffers rows client-side and sends them to ClickHouse.
Typical usage:
batch, err := conn.PrepareBatch(ctx, "INSERT INTO t")
if err != nil { ... }
defer batch.Close() // cleanup if Send is not reached
for ... {
_ = batch.Append(...)
// Optionally flush periodically for native protocol.
// _ = batch.Flush()
}
_ = batch.Send()
Notes: - After Send(), the batch is considered finalized (IsSent() becomes true). Create a new batch to send more rows. - For HTTP protocol, Flush() is currently a no-op. Use Send() to transmit buffered rows.
type BatchColumn ¶
type ColumnType ¶
type Conn ¶
type Conn interface {
Contributors() []string
ServerVersion() (*ServerVersion, error)
Select(ctx context.Context, dest any, query string, args ...any) error
Query(ctx context.Context, query string, args ...any) (Rows, error)
QueryRow(ctx context.Context, query string, args ...any) Row
PrepareBatch(ctx context.Context, query string, opts ...PrepareBatchOption) (Batch, error)
Exec(ctx context.Context, query string, args ...any) error
// Deprecated: use context aware `WithAsync()` for any async operations
AsyncInsert(ctx context.Context, query string, wait bool, args ...any) error
Ping(context.Context) error
Stats() Stats
Close() error
}
type NamedDateValue ¶ added in v2.1.1
type NamedValue ¶
type PrepareBatchOption ¶ added in v2.13.0
type PrepareBatchOption func(options *PrepareBatchOptions)
func WithCloseOnFlush ¶ added in v2.24.0
func WithCloseOnFlush() PrepareBatchOption
WithCloseOnFlush closes the current INSERT and releases the connection whenever Flush is executed.
This can be used to send data incrementally without keeping a server-side INSERT open.
func WithReleaseConnection ¶ added in v2.13.0
func WithReleaseConnection() PrepareBatchOption
WithReleaseConnection releases the underlying connection back to the pool immediately after PrepareBatch.
This is useful for long-lived batches that should not hold a connection open between Flush/Send calls. The driver will reacquire a connection when it needs to transmit data.
type PrepareBatchOptions ¶ added in v2.13.0
type ServerVersion ¶
type ServerVersion = proto.ServerHandshake