oven-sh/bun

Automatically create directories for the path passed to `new Database`

Open

#3,888 opened on Jul 30, 2023

View on GitHub
 (10 comments) (0 reactions) (0 assignees)Rust (4,486 forks)batch import
bun.jsbun:sqliteenhancementgood first issue

Repository metrics

Stars
 (90,348 stars)
PR merge metrics
 (Avg merge 1d 17h) (357 merged PRs in 30d)

Description

What version of Bun is running?

0.7.1

What platform is your computer?

Darwin 21.6.0 x86_64 i386

What steps can reproduce the bug?

  • create a directory called src

  • create a file called a.ts with this contents

    import { Database } from 'bun:sqlite';
    const db = new Database('./i-dont-exist/data.db');
    
  • bun run ./a.ts

  • error should show

What is the expected behavior?

The directory to be created and then the new database file to be created.

What do you see instead?

This error.

➜  paas git:(main) ✗ bun run src/service-registry.ts
136 |     if (anonymous && (flags & constants.SQLITE_OPEN_READONLY) !== 0)
137 |       throw new Error("Cannot open an anonymous database in read-only mode.");
138 |     if (!SQL)
139 |       _SQL = SQL = lazy("sqlite");
140 | 
141 |     this.#handle = SQL.open(anonymous ? ":memory:" : filename, flags), this.filename = filename;
                      ^
error: unable to open database file
      at new Database (bun:sqlite:141:19)
      at /Users/xo/code/ImLunaHey/paas/src/service-registry.ts:3:11

Additional information

No response

Contributor guide