Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,33 @@ sqlite3InitModule({
});
```

## Usage with the bundled `SQLiteClient` (with OPFS if available):

> **Warning** For this to work, you need to set the following headers on your
> server:
>
> `Cross-Origin-Opener-Policy: same-origin`
>
> `Cross-Origin-Embedder-Policy: require-corp`

Import the `@sqlite.org/sqlite-wasm` library in your code and use it as such:

```js
import {SqliteClient} from "@sqlite.org/sqlite-wasm";

// Must correspond to the path in your final deployed build.
const sqliteWorkerPath = 'assets/js/sqlite-worker.js';
// This is the name of your database. It corresponds to the path in the OPFS.
const filename = '/test.sqlite3';

const sqlite = new Sqlite(filename, sqliteWorkerPath)
await sqlite.init();

await sqlite.executeSql("CREATE TABLE IF NOT EXISTS test(a,b)");
await sqlite.executeSql("INSERT INTO test VALUES(?, ?)", [6,7]);
const results = await sqlite.executeSql("SELECT * FROM test");
```

## Usage with vite

If you are using [vite](https://vitejs.dev/), you need to add the following
Expand Down