SeekdbClient
SeekdbClient is the unified interface for connecting to seekdb. It supports embedded seekdb, server-mode seekdb, and OceanBase Database.
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 embedded seekdb
Use SeekdbClient to connect to a local embedded seekdb instance.
import { SeekdbClient } from "seekdb";
// Create embedded client
const client = new SeekdbClient({
path: "./seekdb.db",
database: "test",
});
Parameters:
| Parameter | Value type | Required | Description | Example value |
|---|---|---|---|---|
path | string | No | The path to the seekdb data directory. seekdb stores database files under this path and loads them on startup. | ./seekdb.db |
database | string | No | The database name. | test |
Connect to a remote server
You can use SeekdbClient to connect to a remote server. This client supports connecting to seekdb 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 is located. | 127.0.0.1 |
port | string | Yes | The port of the instance. The default value is 2881. | 2881 |
database | string | Yes | The database name. | test |
user | string | Yes | The username. The default value is root. | root |
password | string | Yes | The password corresponding to 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 is located. | 127.0.0.1 |
port | string | Yes | The port of OceanBase Database. The default value is 2881. | 2881 |
tenant | string | No | The tenant name. You do not need this parameter for seekdb; use it only with OceanBase Database. The default value is sys. | sys |
database | string | Yes | The database name. | demo |
user | string | Yes | The username corresponding to the tenant. The default value is root. | root |
password | string | Yes | The password corresponding to 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 whether collections exist in the current database. | Documentation |
deleteCollection() | Deletes a specified collection. | Documentation |