Skip to content

sql.js

Step 1: Install sql.js

Run the following command to install the sql.js package:

sh
npm i sql.js

Step 2: Configure the dataProvider

In your api.ts or server file, configure the dataProvider to use sql.js:

ts
import express from 'express'
import { remultExpress } from 'remult/remult-express'
import { SqlDatabase } from 'remult'
import initSqlJs from 'sql.js'
import { SqlJsDataProvider } from 'remult/remult-sql-js'

const app = express()

app.use(
  remultExpress({
    dataProvider: new SqlDatabase(
      new SqlJsDataProvider(initSqlJs().then((SQL) => new SQL.Database())),
    ),
  }),
)

Explanation:

  • sql.js: This setup initializes an in-memory SQLite database using sql.js, a library that runs SQLite in the browser or in Node.js.
  • SqlJsDataProvider: The SqlJsDataProvider is used to integrate the sql.js database as a Remult data provider.
  • Async Initialization: The initSqlJs() function initializes the SQL.js engine and sets up the database instance.

This configuration allows you to use an in-memory SQLite database in your Remult application, powered by sql.js.

MIT Licensed | Made by the Remult team with ❤️