surrealdb / surrealdb.wasm

A WebAssembly engine for the SurrealDB JavaScript SDK

Home Page:https://surrealdb.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


 

A WebAssembly engine for the SurrealDB JavaScript SDK.


   

     

@surrealdb/wasm

A WebAssembly engine for the SurrealDB JavaScript SDK.

This library is a plugin for the SurrealDB JavaScript SDK, which can be used to run SurrealDB as an embedded database within a browser environment, not server side environments.

It enables SurrealDB to be run in-memory, or to persist data by running on top of IndexedDB. It allows for a consistent JavaScript and TypeScript API when using the surrealdb.js library by adding support for embedded storage engines (memory, indxdb) alongside the remote connection protocols (http, https, ws, wss).

This library works with ES modules (import), not CommonJS (require).

Example usage

import { Surreal } from 'surrealdb';
import { surrealdbWasmEngines } from '@surrealdb/wasm';

// Enable the WebAssembly engines
const db = new Surreal({
    engines: surrealdbWasmEngines(),
});

// Now we can start SurrealDB as an in-memory database
await db.connect("mem://");
// Or we can start a persisted IndexedDB database
await db.connect("indxdb://demo");

// Now use the JavaScript SDK as normal.

Usage with Vite

When using Vite the following configuration is recommended to be placed in your vite.config.ts

optimizeDeps: {
    exclude: ['@surrealdb/wasm', 'surrealql.wasm'],
    esbuildOptions: {
        target: 'esnext',
    },
},
esbuild: {
    supported: {
        'top-level-await': true
    },
}

About

A WebAssembly engine for the SurrealDB JavaScript SDK

https://surrealdb.com

License:Apache License 2.0


Languages

Language:Rust 54.6%Language:TypeScript 23.8%Language:JavaScript 14.7%Language:HTML 4.2%Language:Makefile 2.6%