loadFromUrl static method

Future<WasmSqlite3> loadFromUrl(
  1. Uri uri,
  2. {Map<String, String>? headers}
)

Loads a web version of the sqlite3 libraries.

The native wasm library for sqlite3 is loaded from the uri with the desired headers through a fetch request.

The environment can optionally be set to use a custom virtual file system. By default, all databases opened are stored in memory only (this includes databases opened with a path in open).

Implementation

static Future<WasmSqlite3> loadFromUrl(
  Uri uri, {
  Map<String, String>? headers,
}) async {
  FetchOptions? options;

  if (headers != null) {
    final headersJs = newObject<Object>();
    headers.forEach((key, value) {
      setProperty(headersJs, key, value);
    });

    options = FetchOptions(headers: headers);
  }

  final jsUri = uri.isAbsolute
      ? URL.absolute(uri.toString())
      : URL.relative(uri.toString(), Uri.base.toString());
  final response = await promiseToFuture<Response>(fetch(jsUri, options));
  return _load(response);
}