otsutils

package module
v0.0.0-...-a691d59 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2025 License: AGPL-3.0 Imports: 8 Imported by: 0

README

otsutils

util for Alibaba Cloud OTS https://www.aliyun.com/product/ots

Documentation

Overview

Package otsutils provides utilities for working with Alibaba Cloud Tablestore (OTS).

Package otsutils provides utilities for working with Alibaba Cloud Tablestore (OTS).

Package otsutils provides utilities for working with Alibaba Cloud Tablestore (OTS).

Package otsutils provides utilities for working with Alibaba Cloud Tablestore (OTS).

Package otsutils provides utilities for working with Alibaba Cloud Tablestore (OTS).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRow

func GetRow(ctx context.Context, obj any, params ...GetRowParams) error

GetRow retrieves a row from the table. The obj parameter should be a pointer to a struct with fields tagged with "json" and "pk". Fields tagged with "pk" are used to locate the row, and other fields are populated with the retrieved values.

Example usage:

type MyRow struct {
    PK1 *string `json:"pk1" pk:"1"`
    Col1 *string `json:"col1"`
    Col2 *int64 `json:"col2"`
}

row := MyRow{
    PK1: tea.String("pk1value"),
}
err := GetRow(ctx, &row)
if err == nil {
    // row.Col1 and row.Col2 are now populated with values from the table
}

func NewClient

func NewClient(ctx context.Context, endPoint, instanceName, accessKeyId, accessKeySecret string) *tablestore.TableStoreClient

NewClient creates a new TableStore client with the provided credentials. It will panic if any of the required parameters are empty.

func ParseObj

func ParseObj(ctx context.Context, obj any) (pks []KeyValue, cols []KeyValue, err error)

func ParseResult

func ParseResult(ctx context.Context, obj any, pks []KeyValue, cols []KeyValue) error

func PutRow

func PutRow(ctx context.Context, obj any, params ...PutRowParams) error

PutRow inserts a row into the table. The obj parameter should be a pointer to a struct with fields tagged with "json" and optionally "pk". Fields tagged with "pk" are treated as primary key columns, others are treated as attribute columns.

Example usage:

type MyRow struct {
    PK1 *string `json:"pk1" pk:"1"`
    Col1 *string `json:"col1"`
}

row := MyRow{
    PK1: tea.String("pk1value"),
    Col1: tea.String("col1value"),
}
err := PutRow(ctx, &row)

func UpdateRow

func UpdateRow(ctx context.Context, obj any, params ...UpdateRowParams) error

UpdateRow updates a row in the table. The obj parameter should be a pointer to a struct with fields tagged with "json" and "pk". Fields tagged with "pk" are treated as primary key columns and used to locate the row. Other fields in the struct are treated as attribute columns to update or add.

Example usage:

type MyRow struct {
    PK1 *string `json:"pk1" pk:"1"`
    Col1 *string `json:"col1"`
    Col2 *int64 `json:"col2"`
}

row := MyRow{
    PK1: tea.String("pk1value"),
    Col1: tea.String("newcol1value"),
    Col2: tea.Int64(42),
}

expectExist := tablestore.RowExistenceExpectation_EXPECT_EXIST
err := UpdateRow(ctx, &row, UpdateRowParams{
    RowExistenceExpectation: &expectExist,
    DeletedColumns: []string{"old_column"},
})

Types

type GetRowParams

type GetRowParams struct {
}

GetRowParams contains parameters for the GetRow operation.

type KeyValue

type KeyValue struct {
	Key   string
	Value any
}

KeyValue represents a key-value pair.

type OtsUtilsParams

type OtsUtilsParams struct {
	Client    *tablestore.TableStoreClient
	TableName string
}

OtsUtilsParams holds the TableStore client and table name.

func OtsUtilsParamsFromCtx

func OtsUtilsParamsFromCtx(ctx context.Context) *OtsUtilsParams

OtsUtilsParamsFromCtx retrieves the OtsUtilsParams from the context.

func (*OtsUtilsParams) WithContext

func (otsUtilsParams *OtsUtilsParams) WithContext(ctx context.Context) context.Context

WithContext adds the OtsUtilsParams to the context. It will panic if TableName or Client are not set.

type PutRowParams

type PutRowParams struct {
	// RowExistenceExpectation specifies the row existence expectation for the operation.
	RowExistenceExpectation *tablestore.RowExistenceExpectation
}

PutRowParams contains parameters for the PutRow operation.

type UpdateRowParams

type UpdateRowParams struct {
	// RowExistenceExpectation specifies the row existence expectation for the operation.
	RowExistenceExpectation *tablestore.RowExistenceExpectation

	// DeletedColumns is a list of column names to delete.
	DeletedColumns []string

	// UpdatedColumns is a map of column names to values to update or add.
	UpdatedColumns map[string]any
}

UpdateRowParams contains parameters for the UpdateRow operation.

Jump to

Keyboard shortcuts

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