@tai-kun/surrealdb
v2.1.2
Published
The SurrealDB SDK for JavaScript
Downloads
595
Readme
A modular SurrealDB client working in major JavaScript runtimes.
[!NOTE] The main branch is currently under development for SurrealDB v2. You can find the repository for SurrealDB v1 here.
Document (JA/EN/KO/zh-CN)
https://tai-kun.github.io/surrealdb.js/getting-started/
Install
npm i @tai-kun/surrealdb
Quick Start
import { Surreal } from "@tai-kun/surrealdb";
const db = new Surreal();
await db.connect("<your_surrealdb_server>"); // e.g. ws://localhost:8000
try {
await db.signin({ user: "root", pass: "root" });
await db.use("sample_namespace", "sample_database");
const results = await db.query<[number]>(/*surql*/ `RETURN 42;`);
console.log(results); // [ 42 ]
} finally {
await db.close();
}
Customization
import { initSurreal } from "@tai-kun/surrealdb";
import Client from "@tai-kun/surrealdb/standard-client";
import HttpEngine from "@tai-kun/surrealdb/http-engine";
import JsonFormatter from "@tai-kun/surrealdb/json-formatter";
const { Surreal } = initSurreal({
Client: Client,
engines: {
http: config => new HttpEngine({
...config,
// fetch: <your custom fetch function>
}),
https: "http",
},
formatter: new JsonFormatter(),
});
Requirements
SurrealDB v2
The repository for SurrealDB v1 is here.
Recommended environment
| Env | Version |
| --- | --- |
| Node.js | 20.x
,22.x
*1 |
| Deno | 1.x
, 2.x
*2 |
| Bun | 1.x
|
| Chromium | >=104
*3 |
| Firefox | >=100
*4 |
| WebKit | >=15.4
*5 |
*1: Probably works with 18.x
*2: Probably works with ^1.44.3
*3: Probably works with >=78
*4: Probably works with >=68
*5: Probably works with >=14
Fully Tested
| Env | Version |
| --- | --- |
| Node.js | 20.x
,22.x
,23.x
|
| Deno | 1.x
,2.x
|
| Bun | 1.x
|
| Chromium | >=104
|
Partial Tested
| Env | Version |
| --- | --- |
| Node.js | 18.x
|
| Firefox | >=100
|
| WebKit | >=15.4
|