Skip to content

zhihu/zetta-client-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zetta TableStore Go Client

Installation

$ go get github.com/zhihu/zetta-client-go

Example Usage

Create Table

cfs := []*tspb.ColumnFamilyMeta{
    {
        Id:         0,
        Name:       "default",
        Attributes: nil,
    },
}
cs := []*tspb.ColumnMeta{
    {
        Id:         0,
        Name:       "name",
        ColumnType: &tspb.Type{Code: tspb.TypeCode_STRING},
        IsPrimary:  true,
        NotNull:    false,
        Family:     "default",
    },
    {
        Id:         1,
        Name:       "age",
        ColumnType: &tspb.Type{Code: tspb.TypeCode_STRING},
        IsPrimary:  false,
        NotNull:    false,
        Family:     "default",
    },
}
tableMeta := &tspb.TableMeta{
    TableName:       "users",
    ColumnFamilies:  cfs,
    Columns:         cs,
    PrimaryKey:      []string{"name"}, // there must be a PK
    Attributes:      nil,
    Interleave:      nil,
    ExtraStatements: nil,
}
if err := adminClient.CreateTable(ctx, DB_NAME, tableMeta, nil); err != nil {
    panic(err)
}

Simple Writes

TABLE_NAME := "users"
cols := []string{"name", "age"}
vals := []interface{}{"user-01", "18"}
rawMS := zetta.InsertOrUpdate(TABLE_NAME, cols, vals)
err := client.Mutate(context.Background(), rawMS)
if err != nil {
    panic(err)
}

Simple Reads

keys := zetta.KeySet{
    Keys: []zetta.Key{[]interface{}{"user-01"}},
}
resp, err := client.Read(context.Background(), "users", keys, "", []string{"name", "age"}, 10)
if err != nil {
    panic(err)
}
for _, row := range resp.SliceRows {
    if len(row.GetCells()) != 2 {
        panic("invalid values")
    }
    name := row.Cells[0].GetValue()
    age := row.Cells[1].GetValue()

    fmt.Println("read name:", name.GetStringValue())
    fmt.Println("read age:", age.GetStringValue())
}

About

Go client for Zetta Table Store

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages