oven-sh/bun

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

Open

#3888 aperta il 30 lug 2023

Vedi su GitHub
 (10 commenti) (0 reazioni) (0 assegnatari)Rust (4486 fork)batch import
bun.jsbun:sqliteenhancementgood first issue

Metriche repository

Star
 (90.348 star)
Metriche merge PR
 (Merge medio 1g 17h) (357 PR mergiate in 30 g)

Descrizione

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

Guida contributor