sdk

package
v1.17.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrParseParamFmt         = "dsn parse error, name: %v, type: %T, given: %v, error: %s"
	ErrDsnMissingSecretKey   = errors.New("missing secret key in dsn")
	ErrDsnMissingRegion      = errors.New("missing region in dsn")
	ErrTokenAuthNotSupported = errors.New("token authentication not supported")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config is a configuration parsed from a DSN string.

func ParseDSN

func ParseDSN(dsn string, hostOverride HostOverride, logf Logf) (*Config, error)

ParseDSN returns a new config used to connect to database

type Conn

type Conn interface {
	// QueryContext sends a query and returns a QueryResult
	// The query result can be used to export to a file
	QueryContext(ctx context.Context, query string) (*QueryResult, error)
	// QueryContextWithExternalTable sends a query with an external table
	// The name of the external table in the query has to correspond to that in the externalTable you are sending
	QueryContextWithExternalTable(ctx context.Context, query string, externalTable *ExternalTable) (*QueryResult, error)
	// QueryContextWithExternalTable sends a query with an external table from an io.Reader (can be a file)
	// The name of the external table in the query has to correspond to that in the externalTable you are sending
	QueryContextWithExternalTableReader(ctx context.Context, query string, externalTable *ExternalTableReader) (*QueryResult, error)
	// PrepareContext is used for batch insertion
	// PrepareContext sends the query to the database and return a Stmt interface
	// The Stmt interface can be used to send the arguments for the query
	PrepareContext(ctx context.Context, query string) (Stmt, error)
	// InsertFromReader inserts data from io.Reader
	// Can be used for insert with files such as csv or json
	// DataPacket will be read from the reader until io.EOF is returned as an error from reader.Read()
	InsertFromReader(ctx context.Context, query string, reader io.Reader) (int, error)
}

type ExternalTable

type ExternalTable struct {
	// contains filtered or unexported fields
}

func NewExternalTable

func NewExternalTable(name string, values [][]interface{}, columnNames []string, columnTypes []column.CHColumnType) *ExternalTable

ExternalTableFromReader creates an external table columnTypes are the clickhouse column type for each column in the table, e.g. UInt8, Uint32, etc values are the table values The type of each column in values table must correspond to the columnTypes specified

func (*ExternalTable) ToSingleBlockStream

func (e *ExternalTable) ToSingleBlockStream() (<-chan *data.Block, error)

type ExternalTableReader

type ExternalTableReader struct {
	// contains filtered or unexported fields
}

func NewExternalTableReader

func NewExternalTableReader(name string, reader io.Reader, columnNames []string, columnTypes []column.CHColumnType, fileType string) *ExternalTableReader

NewExternalTableReader creates an external table from a file It parses the data according to the fileType The type of each column in the file must correspond to the columnTypes specified Column types are the clickhouse column type for each column in the table, e.g. UInt8, Uint32, etc Supported fileType values are CSV, CSVWithNames, JSON, VALUES

type Gateway

type Gateway struct {
	Conn *conn.GatewayConn
}

func Open

func Open(ctx context.Context, dsn string) (*Gateway, error)

func OpenConfig

func OpenConfig(config *Config) *Gateway

func (*Gateway) Clone

func (g *Gateway) Clone() *Gateway

func (*Gateway) Close

func (g *Gateway) Close() error

Close exposed for SDK directly

func (*Gateway) Closed

func (g *Gateway) Closed() bool

func (*Gateway) InsertArgs

func (g *Gateway) InsertArgs(ctx context.Context, query string, batchSize int, args ...interface{}) error

func (*Gateway) InsertFromReader

func (g *Gateway) InsertFromReader(ctx context.Context, query string, file io.Reader) (int, error)

func (*Gateway) InsertTable

func (g *Gateway) InsertTable(ctx context.Context, query string, table [][]interface{}, batchSize int) error

func (*Gateway) InsertWithData

func (g *Gateway) InsertWithData(ctx context.Context, query string, dataReader io.Reader, dataFmt string, blockSize int) (*QueryResult, error)

func (*Gateway) InsertWithDataFormatAuto

func (g *Gateway) InsertWithDataFormatAuto(ctx context.Context, query string, dataReader io.Reader) (*QueryResult, error)

InsertWithDataFormatAuto handles insert Query with data reader

func (*Gateway) Ping

func (g *Gateway) Ping() error

Ping exposed for SDK directly

func (*Gateway) PrepareContext

func (g *Gateway) PrepareContext(ctx context.Context, query string) (Stmt, error)

func (*Gateway) PrepareInsert

func (g *Gateway) PrepareInsert(ctx context.Context, query string, batchSize int) (*InsertStmt, error)

PrepareInsert returns an Insert Statement that must be closed after use.

func (*Gateway) PrepareMultiConnectionInsert

func (g *Gateway) PrepareMultiConnectionInsert(ctx context.Context, query string, batchSize, connCount int) (*MultiInsertStatement, error)

func (*Gateway) Query

func (g *Gateway) Query(query string) (*QueryResult, error)

func (*Gateway) QueryContext

func (g *Gateway) QueryContext(ctx context.Context, query string) (*QueryResult, error)

func (*Gateway) QueryContextWithExternalTable

func (g *Gateway) QueryContextWithExternalTable(ctx context.Context, query string, externalTable *ExternalTable) (*QueryResult, error)

func (*Gateway) QueryContextWithExternalTableReader

func (g *Gateway) QueryContextWithExternalTableReader(ctx context.Context, query string, externalTable *ExternalTableReader) (*QueryResult, error)

func (*Gateway) SendInsertQuery

func (g *Gateway) SendInsertQuery(ctx context.Context, query string) error

SendInsertQuery sends a prepared query to database Used before insertion of rows

type HostOverride

type HostOverride func() (host string, err error)

type InsertStmt

type InsertStmt struct {
	// contains filtered or unexported fields
}

func NewInsertStatement

func NewInsertStatement(
	ctx context.Context, sample *data.Block,
	sendBlock stream.SendBlock, cancelInsert stream.CancelInsert,
	serverResponseStream <-chan response.Packet,
	opts ...stream.InsertOption,
) *InsertStmt

func (*InsertStmt) Close

func (s *InsertStmt) Close() error

func (*InsertStmt) Exec

func (s *InsertStmt) Exec(args ...interface{}) (err error)

func (*InsertStmt) ExecContext

func (s *InsertStmt) ExecContext(ctx context.Context, args ...interface{}) (err error)

type Logf

type Logf func(s string, args ...interface{})

type MultiInsertStatement

type MultiInsertStatement struct {
	// contains filtered or unexported fields
}

MultiInsertStatement that stores multiple Insert Statements attached to multiple connection. ExecContext can be done asynchronously. insertion load is distributed across insert stmts, switching from insert stmts happens when the columns buffer is at its full capacity(batch size).

func NewMultiInsertStatement

func NewMultiInsertStatement(stmts []*InsertStmt, close closeAllConnection) (*MultiInsertStatement, error)

func (*MultiInsertStatement) Close

func (m *MultiInsertStatement) Close() error

func (*MultiInsertStatement) ExecContext

func (m *MultiInsertStatement) ExecContext(ctx context.Context, args ...interface{}) error

func (*MultiInsertStatement) Switch

func (m *MultiInsertStatement) Switch()

type QueryResult

type QueryResult struct {
	// contains filtered or unexported fields
}

func NewInsertQueryResult

func NewInsertQueryResult(responses <-chan response.Packet) *QueryResult

func NewQueryResult

func NewQueryResult(responses <-chan response.Packet, finish func()) *QueryResult

func (*QueryResult) Close

func (q *QueryResult) Close() error

func (*QueryResult) Columns

func (q *QueryResult) Columns() []*column.CHColumn

func (*QueryResult) Exception

func (q *QueryResult) Exception() error

func (*QueryResult) ExportToReader

func (q *QueryResult) ExportToReader(fmtType string) io.Reader

func (*QueryResult) GetAllLogs

func (q *QueryResult) GetAllLogs() []*response.LogPacket

func (*QueryResult) GetAllMeta

func (q *QueryResult) GetAllMeta() []response.Packet

func (*QueryResult) NextRow

func (q *QueryResult) NextRow() ([]interface{}, bool)

func (*QueryResult) NextRowAsString

func (q *QueryResult) NextRowAsString() ([]interface{}, bool)

type Stmt

type Stmt interface {
	// ExecContext is used to send a row of query argument to the clickhouse server
	ExecContext(ctx context.Context, args ...interface{}) error
	// Close sends leftover queued query arguments to the clickhouse server and closes the stmt
	// Close has to be called at the end for each Stmt
	Close() error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL