Skip to content

Go客户端概况

IHEII edited this page Aug 21, 2023 · 3 revisions

Client接口

type Client interface {
	// Insert a record by rowKey.
	Insert(ctx context.Context, tableName string, rowKey []*table.Column, mutateColumns []*table.Column, opts ...option.ObOperationOption) (int64, error)
	// Update a record by rowKey.
	Update(ctx context.Context, tableName string, rowKey []*table.Column, mutateColumns []*table.Column, opts ...option.ObOperationOption) (int64, error)
	// InsertOrUpdate insert or update a record by rowKey.
	// insert if the primary key does not exist, update if it does.
	InsertOrUpdate(ctx context.Context, tableName string, rowKey []*table.Column, mutateColumns []*table.Column, opts ...option.ObOperationOption) (int64, error)
	// Replace a record by rowKey.
	Replace(ctx context.Context, tableName string, rowKey []*table.Column, mutateColumns []*table.Column, opts ...option.ObOperationOption) (int64, error)
	// Increment a record by rowKey.
	Increment(ctx context.Context, tableName string, rowKey []*table.Column, mutateColumns []*table.Column, opts ...option.ObOperationOption) (SingleResult, error)
	// Append a record by rowKey.
	Append(ctx context.Context, tableName string, rowKey []*table.Column, mutateColumns []*table.Column, opts ...option.ObOperationOption) (SingleResult, error)
	// Delete a record by rowKey.
	Delete(ctx context.Context, tableName string, rowKey []*table.Column, opts ...option.ObOperationOption) (int64, error)
	// Get a record by rowKey.
	Get(ctx context.Context, tableName string, rowKey []*table.Column, getColumns []string, opts ...option.ObOperationOption) (SingleResult, error)
	// Query records by rangePairs.
	Query(ctx context.Context, tableName string, rangePairs []*table.RangePair, opts ...option.ObQueryOption) (QueryResultIterator, error)
	// NewBatchExecutor create a batch executor.
	NewBatchExecutor(tableName string, opts ...option.ObBatchOption) BatchExecutor
	// NewAggExecutor create an aggregate executor.
	NewAggExecutor(tableName string, rangePairs []*table.RangePair, opts ...option.ObQueryOption) AggExecutor
	// Close closes the client.
	// close will disconnect all connections and exit all goroutines.
	Close()
}
  • Insert: 写入一条记录
  • Update: 更新一条记录
  • InsertOrUpdate: 写入或更新一条记录(主键不存在时写入,主键存在时更新)
  • Replace: 替换一条记录
  • Increment: 对记录中的某些整型列进行自增,mutateColumns代表的是增加的delta值,可以使用func WithReturnAffectedEntity(returnAffectedEntity bool) ObkvOption方法返回增加后的值,delta值只支持signed类型
  • Append: 对记录中的某些字符串列进行追加,mutateColumns代表的是增加的delta值,可以使用func WithReturnAffectedEntity(returnAffectedEntity bool) ObkvOption方法返回增加后的值
  • Delete: 删除一条记录
  • Get: 获取一条记录
  • Query: 获取一批记录
  • NewBatchExecutor: 创建一个批量执行器
  • NewAggExecutor: 获取一个聚合操作执行器
  • Close: 关闭客户端

Column代表表中的一列,有列名和列值两个属性。

type Column struct {
	name  string
	value interface{}
}

我们提供了构造列的方法

func NewColumn(name string, value interface{}) *Column {
	return &Column{name: name, value: value}
}
Clone this wiki locally