Files
moeka-project/packages/duckdb-wasm

Easy to use @duckdb/duckdb-wasm wrapper for both browser and Node.js environments

Playground

Installation

Pick the package manager of your choice:

ni @proj-airi/duckdb-wasm -D # from @antfu/ni, can be installed via `npm i -g @antfu/ni`
pnpm i @proj-airi/duckdb-wasm -D
yarn i @proj-airi/duckdb-wasm -D
npm i @proj-airi/duckdb-wasm -D

Usage

Browser

<script setup lang="ts">
import type { DuckDBWasmClient } from '@proj-airi/duckdb-wasm'

import { connect, getEnvironment } from '@proj-airi/duckdb-wasm'
import { getImportUrlBundles } from '@proj-airi/duckdb-wasm/bundles/import-url-browser'
import { onMounted, onUnmounted, ref } from 'vue'

const db = ref<DuckDBWasmClient>()

onMounted(async () => {
  db.value = await connect({ bundles: getImportUrlBundles })
  const result = await db.value.conn.query('SELECT 1 + 1 AS res')
  console.log(result) // Output: [{ res: 2 }]
})

onUnmounted(() => {
  db.value?.close()
})
</script>

Node.js

You will need to install web-worker too.

ni web-worker # from @antfu/ni, can be installed via `npm i -g @antfu/ni`
pnpm i web-worker
yarn i web-worker
npm i web-worker
import { connect, getEnvironment } from '@proj-airi/duckdb-wasm'
import { getImportUrlBundles } from '@proj-airi/duckdb-wasm/bundles/default-node'

async function main() {
  const { conn, close } = await connect({ bundles: getImportUrlBundles })
  const result = await conn.query('SELECT 1 + 1 AS res')
  console.log(result) // Output: [{ res: 2 }]

  await close()
}