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.
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:
- configUrl is generated by ConfigServer.
- fullUserName: the user for accessing obkv, which format is
user_name@tenant_name#cluster_name
- passWord: the password of user in fullUserName.
- sysUserName:
root
orproxy
, which have privileges to access routing system view - sysPassWord: the password of sys user in sysUserName.
- English [Coming soon]
- Simplified Chinese (简体中文)
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.
Contributions are warmly welcomed and greatly appreciated. Here are a few ways you can contribute:
- Raise us an Issue
- Submit Pull Requests. For details, see How to contribute.
In case you have any problems when using OceanBase Database, welcome reach out for help:
- GitHub Issue GitHub Issue
- Official forum Official website
- Knowledge base [Coming soon]