Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make data-server usable as a websocket library #236

Closed
mingfang opened this issue Dec 24, 2023 · 1 comment · Fixed by #237
Closed

make data-server usable as a websocket library #236

mingfang opened this issue Dec 24, 2023 · 1 comment · Fixed by #237

Comments

@mingfang
Copy link
Contributor

Currently the data-server websocker standalone server is standalone.
Sometimes that's not desirable because you already have your own server, e.g. Express.
To make data-server usable in Express, we need to export queryHandler and socketResponse.

@mingfang
Copy link
Contributor Author

mingfang commented Dec 24, 2023

Here is an example use case with Express

import express from 'express'
import expressWebsockets from "express-ws"
import { DuckDB, Cache, queryHandler, socketResponse } from "@uwdata/mosaic-duckdb"

const { app } = expressWebsockets(express())
const db = new DuckDB()
const CACHE_DIR = '.mosaic/cache'
const queryCache = new Cache({ dir: CACHE_DIR })
const handleQuery = queryHandler(db, queryCache)
app.ws("/duckdb-ws", (websocket, request) => {
    const res = socketResponse(websocket)
    websocket.on('message', data => handleQuery(res, data))
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant