An open API service indexing awesome lists of open source software.

https://github.com/proj-airi/duckdb-wasm

🦆📊 Easy to use wrapper and Drizzle ORM driver for DuckDB WASM
https://github.com/proj-airi/duckdb-wasm

database drizzle-orm duckdb-wasm memory orm proj-airi

Last synced: 4 months ago
JSON representation

🦆📊 Easy to use wrapper and Drizzle ORM driver for DuckDB WASM

Awesome Lists containing this project

README

          

DuckDB WASM


Easy to use wrapper and Drizzle ORM driver for DuckDB WASM

Web browser based [Playground](https://drizzle-orm-duckdb-wasm.netlify.app/), try it!

> [!NOTE]
>
> This project is part of (and also associate to) the [Project AIRI](https://github.com/moeru-ai/airi), we aim to build a LLM-driven VTuber like [Neuro-sama](https://www.youtube.com/@Neurosama) (subscribe if you didn't!) if you are interested in, please do give it a try on [live demo](https://airi.moeru.ai).
>
> We use both DuckDB WASM and PGLite for the backbone implementation for memory layer as embedded databases that capable of doing vector search to power up bionic memory systems for AI VTuber and cyber livings. We shared a lot in our [DevLogs](https://airi.moeru.ai/docs/blog/devlog-20250305/) in [DevLog @ 2025.04.06](https://airi.moeru.ai/docs/blog/devlog-20250406/), please read it if you are interested in!
>
> Who are we?
>
> We are a group of currently non-funded talented people made up with computer scientists, experts in multi-modal fields, designers, product managers, and popular open source contributors who loves the goal of where we are heading now.

> [!NOTE]
>
> **Usage notes (as of Apr 12, 2025)**
>
> While using `@proj-airi/duckdb-wasm` directly or indirectly with Vite, you may encounter the following error:
>
> ```
> Cannot read file: .../node_modules/.pnpm/@duckdb+duckdb-wasm@1.29.1-dev68.0/node_modules/@duckdb/duckdb-wasm/dist/duckdb-browser-mvp.worker.js?url
>
> node_modules/.pnpm/@proj-airi+duckdb-wasm@0.4.21/node_modules/@proj-airi/duckdb-wasm/dist/bundles/import-url-browser.mjs:3:26:
> 3 │ import mvpMainWorker from '@duckdb/duckdb-wasm/dist/duckdb-browser-mvp.worker.js?url';
> ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ```
>
> This is due to an open issue with Vite, as a workaround, you can try excluding `@proj-airi/duckdb-wasm` in `optimizeDeps` in your
> `vite.config.ts`:
>
> ```ts
> export default defineConfig({
> // ...
> optimizeDeps: {
> exclude: ['@proj-airi/duckdb-wasm']
> }
> })
> ```
>
> See also: https://github.com/vitejs/vite/issues/10838

## Usage

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

```typescript
import { drizzle } from '@proj-airi/drizzle-duckdb-wasm'

const db = drizzle('duckdb-wasm://?bundles=import-url', { schema })
const results = await db.execute('SELECT count(*)::INTEGER as v FROM generate_series(0, 100) t(v)')
console.log(results) // Output [{ v: 101 }]

// Remember to close / dispose the resources.
await db.$client.close()
```

## Packages

- [`@proj-airi/drizzle-duckdb-wasm`](https://github.com/proj-airi/duckdb-wasm/tree/main/packages/drizzle-duckdb-wasm/README.md): [Drizzle ORM](https://orm.drizzle.team/) driver for [DuckDB WASM](https://github.com/duckdb/duckdb-wasm)
- [`@proj-airi/duckdb-wasm`](https://github.com/proj-airi/duckdb-wasm/tree/main/packages/duckdb-wasm/README.md): Easy to use wrapper for [`@duckdb/duckdb-wasm`](https://github.com/duckdb/duckdb-wasm)

## Development

```shell
pnpm i
```

Start the Drizzle DuckDB WASM playground locally:

```shell
pnpm -F @proj-airi/drizzle-duckdb-wasm play:dev
```

> [!NOTE]
>
> For [@antfu/ni](https://github.com/antfu-collective/ni) users, you can
>
> ```shell
> nr -F @proj-airi/drizzle-duckdb-wasm play:dev
> ```