Skip to content

oceanbase/obkv-table-client-go

Repository files navigation

obkv-table-client-go

OBKV Table Client is go Library that can be used to access table data from OceanBase storage layer. Its access method is different from JDBC, it skips the SQL parsing layer, so it has significant performance advantage.

Quick Start

Create table in the OceanBase database:

CREATE TABLE IF NOT EXISTS `test` (
    `c1` bigint(20) NOT NULL,
    `c2` bigint(20) NOT NULL,
    PRIMARY KEY (`c1`)
) PARTITION BY KEY(`c1`) PARTITIONS 10;

The code demo:

    const (
		configUrl    = "ob-configserver-url"
		fullUserName = "user@tenant#cluster"
		passWord     = ""
		sysUserName  = "root"
		sysPassWord  = ""
		tableName    = "test"
	)

	cfg := config.NewDefaultClientConfig()
	cli, err := client.NewClient(configUrl, fullUserName, passWord, sysUserName, sysPassWord, cfg)
	if err != nil {
		panic(err)
	}

	// insert
	rowKey := []*table.Column{table.NewColumn("c1", int64(1))}
	insertColumns := []*table.Column{table.NewColumn("c2", int64(2))}
	affectRows, err := cli.Insert(
		context.TODO(),
		tableName,
		rowKey,
		insertColumns,
	)
	if err != nil {
		panic(err)
	}
	fmt.Println(affectRows)

	// get
	selectColumns := []string{"c1", "c2"}
	result, err := cli.Get(
		context.TODO(),
		tableName,
		rowKey,
		selectColumns,
	)
	if err != nil {
		panic(err)
	}
	fmt.Println(result.Value("c1"))
	fmt.Println(result.Value("c2"))

NOTE:

  1. configUrl is generated by ConfigServer.
  2. fullUserName: the user for accessing obkv, which format is user_name@tenant_name#cluster_name
  3. passWord: the password of user in fullUserName.
  4. sysUserName: root or proxy, which have privileges to access routing system view
  5. sysPassWord: the password of sys user in sysUserName.

Documentation

Licencing

obkv-table-client-go is under MulanPSL - 2.0 licence. You can freely copy and use the source code. When you modify or distribute the source code, please obey the MulanPSL - 2.0 licence.

Contributing

Contributions are warmly welcomed and greatly appreciated. Here are a few ways you can contribute:

Support

In case you have any problems when using OceanBase Database, welcome reach out for help: