@surrealdb/wasm

1.0.2 • Public • Published

 

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'],
    esbuildOptions: {
        target: 'esnext',
    },
},
esbuild: {
    supported: {
        'top-level-await': true
    },
}

Readme

Keywords

none

Package Sidebar

Install

npm i @surrealdb/wasm

Weekly Downloads

200

Version

1.0.2

License

none

Unpacked Size

10.2 MB

Total Files

9

Last publish

Collaborators

  • kearfy
  • tobiemh