SeekdbClient
SeekdbClient is a unified interface for connecting to seekdb. It supports both seekdb server mode and OceanBase mode.
OceanBase Database is a fully self-developed, enterprise-level native distributed database provided by OceanBase. It achieves financial-grade high availability on ordinary hardware and sets a new standard for automatic, lossless disaster recovery at the city level with its "five IDCs across three regions" architecture. It has also set new records in TPC-C benchmark tests, with a single cluster size exceeding 1,500 nodes. OceanBase Database features cloud-native architecture, strong consistency, and high compatibility with Oracle and MySQL. For more information about OceanBase Database, see OceanBase Database.
Connect to a remote server
You can use SeekdbClient to connect to a remote server. This client supports connecting to the seekdb database and OceanBase Database.
Before you connect to a remote server, make sure that you have deployed the server mode of seekdb or OceanBase Database.
For information about how to deploy the server mode of seekdb, see Deploy seekdb by using yum install.
For information about how to deploy OceanBase Database, see Overview.
Example: Connect to the server mode of seekdb.
import { SeekdbClient } from "seekdb";
// 1. Connect
const client = new SeekdbClient({
host: "127.0.0.1",
port: 2881,
user: "root",
password: "",
database: "test",
});
Parameters:
| Parameter | Value type | Required | Description | Example value |
|---|---|---|---|---|
host | string | Yes | The IP address of the server where the instance resides. | 127.0.0.1 |
port | string | Yes | The port of the instance. The default value is 2881. | 2881 |
database | string | Yes | The name of the database. | test |
user | string | Yes | The username. The default value is root. | root |
password | string | Yes | The password of the user. If you do not specify the password parameter or specify an empty string, the system retrieves the password from the SEEKDB_PASSWORD environment variable. |
Example: Connect to OceanBase Database.
import { SeekDBClient } from "seekdb";
const client = new SeekDBClient({
host: "127.0.0.1", // The IP address of the server where the database resides.
port: 2881, // The port of the database.
tenant: "sys", // The name of the tenant. This parameter is required when you connect to OceanBase Database.
database: "demo", // The name of the database.
user: "root", // The username.
password: "", // The password.
});
Parameters:
| Parameter | Value type | Required | Description | Example value |
|---|---|---|---|---|
host | string | Yes | The IP address of the server where the database resides. | 127.0.0.1 |
port | string | Yes | The port of OceanBase Database. The default value is 2881. | 2881 |
tenant | string | No | The name of the tenant. This parameter is required when you connect to OceanBase Database. The default value is sys. | sys |
database | string | Yes | The name of the database. | demo |
user | string | Yes | The username of the tenant. The default value is root. | root |
password | string | Yes | The password of the user. |
Supported APIs for connecting to the database using SeekdbClient
When connecting to the database using SeekdbClient, the following APIs are supported.
| API | Description | Related document link |
|---|---|---|
createCollection() | Creates a new collection. | Documentation |
getCollection() | Queries a specified collection. | Documentation |
getOrCreateCollection() | Queries a specified collection. If the collection does not exist, it will be created. | Documentation |
fork() | Copies a specified collection to create a new collection with the same data. | Documentation |
listCollections() | Lists all collections in the current database. | Documentation |
countCollection() | Queries the number of collections in the current database. | Documentation |
hasCollection() | Checks if collections exist in the current database. | Documentation |
deleteCollection() | Deletes a specified collection. | Documentation |