Skip to content

Commit 4d60b6f

Browse files
robobunalii
andauthored
docs: clarify SQLite embed example requires existing database (#25329)
Co-authored-by: Alistair Smith <[email protected]>
1 parent e9e9324 commit 4d60b6f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

docs/bundler/executables.mdx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,15 +412,29 @@ const bytes = await file(icon).arrayBuffer();
412412

413413
### Embed SQLite databases
414414

415-
If your application wants to embed a SQLite database, set `type: "sqlite"` in the import attribute and the `embed` attribute to `"true"`.
415+
If your application wants to embed a SQLite database into the compiled executable, set `type: "sqlite"` in the import attribute and the `embed` attribute to `"true"`.
416+
417+
The database file must already exist on disk. Then, import it in your code:
416418

417419
```ts index.ts icon="/icons/typescript.svg"
418420
import myEmbeddedDb from "./my.db" with { type: "sqlite", embed: "true" };
419421

420422
console.log(myEmbeddedDb.query("select * from users LIMIT 1").get());
421423
```
422424

423-
This database is read-write, but all changes are lost when the executable exits (since it's stored in memory).
425+
Finally, compile it into a standalone executable:
426+
427+
```bash terminal icon="terminal"
428+
bun build --compile ./index.ts --outfile mycli
429+
```
430+
431+
<Note>
432+
The database file must exist on disk when you run `bun build --compile`. The `embed: "true"` attribute tells the
433+
bundler to include the database contents inside the compiled executable. When running normally with `bun run`, the
434+
database file is loaded from disk just like a regular SQLite import.
435+
</Note>
436+
437+
In the compiled executable, the embedded database is read-write, but all changes are lost when the executable exits (since it's stored in memory).
424438

425439
### Embed N-API Addons
426440

0 commit comments

Comments
 (0)