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 {
  web.RequestInit? options;

  if (headers != null) {
    final headersJs = JSObject();
    headers.forEach((key, value) {
      headersJs[key] = value.toJS;
    });

    options = web.RequestInit(headers: headersJs);
  }

  final jsUri = uri.isAbsolute
      ? web.URL(uri.toString())
      : web.URL(uri.toString(), Uri.base.toString());
  final response = await fetch(jsUri, options).toDart;
  return _load(response);
}