Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move hello demo to its own directory #177

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[![wa-sqlite CI](https://github.com/rhashimoto/wa-sqlite/actions/workflows/ci.yml/badge.svg?branch=breaking-changes)](https://github.com/rhashimoto/wa-sqlite/actions/workflows/ci.yml?branch=breaking-changes)

# wa-sqlite
This is a WebAssembly build of SQLite with experimental support for writing SQLite virtual filesystems completely in Javascript. This allows alternative browser storage options such as IndexedDB and Origin Private File System. Applications can opt to use either a synchronous or asynchronous (using Asyncify or JSPI) SQLite library build (an asynchronous build is required for asynchronous extensions).
This is a WebAssembly build of SQLite with support for writing SQLite virtual filesystems completely in Javascript. This allows alternative browser storage options such as IndexedDB and Origin Private File System. Applications can opt to use either a synchronous or asynchronous (using Asyncify or JSPI) SQLite library build (an asynchronous build is required for asynchronous extensions).

[IndexedDB](https://github.com/rhashimoto/wa-sqlite/blob/master/src/examples/IDBBatchAtomicVFS.js) and [Origin Private File System](https://github.com/rhashimoto/wa-sqlite/blob/master/src/examples/OPFSAdaptiveVFS.js) virtual file systems are among the examples provided as proof of concept.
IndexedDB and several Origin Private File System virtual file systems are among the examples provided as proof of concept. A table comparing the different VFS classes is [here](https://github.com/rhashimoto/wa-sqlite/tree/master/src/examples#vfs-comparison).

[Try the demo](https://rhashimoto.github.io/wa-sqlite/demo/?build=asyncify&config=IDBBatchAtomicVFS&reset) or run [benchmarks](https://rhashimoto.github.io/wa-sqlite/demo/benchmarks/?config=asyncify,IDBBatchAtomicVFS;default,OPFSCoopSyncVFS) with a modern desktop web browser. More information is available in the [FAQ](https://github.com/rhashimoto/wa-sqlite/issues?q=is%3Aissue+label%3Afaq+), [discussion forums](https://github.com/rhashimoto/wa-sqlite/discussions), and [API reference](https://rhashimoto.github.io/wa-sqlite/docs/).
[Try the demo](https://rhashimoto.github.io/wa-sqlite/demo/?build=asyncify&config=IDBBatchAtomicVFS&reset) or run [benchmarks]([https://rhashimoto.github.io/wa-sqlite/demo/benchmarks/?config=asyncify,IDBBatchAtomicVFS;default,OPFSCoopSyncVFS](https://rhashimoto.github.io/wa-sqlite/demo/benchmarks/?config=asyncify,IDBBatchAtomicVFS;default,AccessHandlePoolVFS;default,OPFSCoopSyncVFS;asyncify,OPFSAdaptiveVFS;asyncify,OPFSPermutedVFS)) with a modern desktop web browser. More information is available in the [FAQ](https://github.com/rhashimoto/wa-sqlite/issues?q=is%3Aissue+label%3Afaq+), [discussion forums](https://github.com/rhashimoto/wa-sqlite/discussions), and [API reference](https://rhashimoto.github.io/wa-sqlite/docs/).

## Build
The primary motivation for this project is to enable additions to SQLite with only Javascript. Most developers should be able to use the pre-built artifacts in
Expand All @@ -32,7 +32,7 @@ Here are the build steps:
The default build produces ES6 modules + WASM, [synchronous and asynchronous](https://github.com/rhashimoto/wa-sqlite/issues/7) (using Asyncify and JSPI) in `dist/`.

## API
Javascript wrappers for core SQLITE C API functions (and some others) are provided. Some convenience functions are also provided to reduce boilerplate. Here's sample code to load the library and call the API:
Javascript wrappers for core SQLITE C API functions (and some others) are provided. Some convenience functions are also provided to reduce boilerplate. Here is sample code to load the library and call the API:

```javascript
import SQLiteESMFactory from 'wa-sqlite/dist/wa-sqlite.mjs';
Expand All @@ -51,6 +51,8 @@ Javascript wrappers for core SQLITE C API functions (and some others) are provid
hello();
```

There is a slightly more complicated example [here](https://github.com/rhashimoto/wa-sqlite/tree/master/demo/hello) that also shows how to use a virtual filesystem (VFS) for persistent storage.

The [implementation of `sqlite3.exec`](https://github.com/rhashimoto/wa-sqlite/blob/eb6e62584b2864d5029f51c6afe155d71ba0caa8/src/sqlite-api.js#L409-L418) may be of interest to anyone wanting more fine-grained use of SQLite statement objects (e.g. for binding parameters, explicit column datatypes, etc.).

[API reference](https://rhashimoto.github.io/wa-sqlite/docs/)
Expand Down
19 changes: 19 additions & 0 deletions demo/hello/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# hello demo
This is a simpler demo program that may be easier to read for those
who want to see how set up and query the database.

The file hello.js can be loaded either in a Window or Worker context.
By default the Window context will be used. Add the query parameter
"worker" to the URL to use a Worker.

By default the hello.js script loads the Asyncify build and uses
the IDBBatchAtomicVFS filesystem. Modify the imports at the top of
the script to try other combinations. Note that not all combinations
are valid:

* As of May 2024, the JSPI build works only on recent Chromium browsers
behind an experiment flag.
* As of May 2024, OPFSPermutedVFS works only on recent Chromium browsers
as it requires FileSystemSyncAccessHandle "readwrite-unsafe" locking.
* Some VFS classes work only with an asynchronous build (Asyncify or JSPI).
* OPFS VFS classes work only within a Worker.
File renamed without changes.
4 changes: 2 additions & 2 deletions demo/hello.js → demo/hello/hello.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
// (Asyncify or JSPI). As of 2024-05-26, JSPI is only available behind
// a flag on Chromium browsers.
// import SQLiteESMFactory from '../dist/wa-sqlite.mjs';
import SQLiteESMFactory from '../dist/wa-sqlite-async.mjs';
import SQLiteESMFactory from '../../dist/wa-sqlite-async.mjs';
// import SQLiteESMFactory from '../dist/wa-sqlite-jspi.mjs';

// Uncomment one of the following imports to choose a VFS. Note that an
// asynchronous VFS requires an asynchronous build, and an VFS using
// FileSystemSyncAccessHandle (generally any OPFS VFS) will run only
// in a Worker.
import { IDBBatchAtomicVFS as MyVFS } from '../src/examples/IDBBatchAtomicVFS.js';
import { IDBBatchAtomicVFS as MyVFS } from '../../src/examples/IDBBatchAtomicVFS.js';
// import { AccessHandlePoolVFS as MyVFS } from '../src/examples/AccessHandlePoolVFS.js';
// import { OPFSAdaptiveVFS as MyVFS } from '../src/examples/OPFSAdaptiveVFS.js';
// import { OPFSCoopSyncVFS as MyVFS } from '../src/examples/OPFSCoopSyncVFS.js';
Expand Down
1 change: 1 addition & 0 deletions demo/hello/index.html
Loading