2020-06-19 06:28:14 -07:00
|
|
|
/// A version of moor that runs on the web by using [sql.js](https://github.com/sql-js/sql.js)
|
2019-07-03 12:51:56 -07:00
|
|
|
/// You manually need to include that library into your website to use the
|
2019-07-12 01:52:42 -07:00
|
|
|
/// web version of moor. See [the documentation](https://moor.simonbinder.eu/web)
|
|
|
|
/// for a more detailed instruction.
|
2019-06-20 12:04:22 -07:00
|
|
|
@experimental
|
|
|
|
library moor_web;
|
|
|
|
|
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:html';
|
2020-02-16 04:26:25 -08:00
|
|
|
import 'dart:indexed_db';
|
2020-03-23 05:36:08 -07:00
|
|
|
import 'dart:js';
|
2019-06-24 11:06:59 -07:00
|
|
|
|
2019-06-20 12:04:22 -07:00
|
|
|
import 'package:meta/meta.dart';
|
2021-01-31 12:50:12 -08:00
|
|
|
import 'package:stream_channel/stream_channel.dart';
|
2019-06-24 11:06:59 -07:00
|
|
|
|
2019-07-22 03:47:18 -07:00
|
|
|
import 'backends.dart';
|
2019-06-20 12:04:22 -07:00
|
|
|
import 'moor.dart';
|
2019-07-10 10:14:55 -07:00
|
|
|
import 'src/web/binary_string_conversion.dart';
|
2019-07-04 05:30:16 -07:00
|
|
|
import 'src/web/sql_js.dart';
|
2019-06-20 12:04:22 -07:00
|
|
|
|
2020-02-16 04:26:25 -08:00
|
|
|
part 'src/web/storage.dart';
|
2019-07-04 05:30:16 -07:00
|
|
|
part 'src/web/web_db.dart';
|
2021-01-31 12:50:12 -08:00
|
|
|
|
|
|
|
/// Extension to transform a raw [MessagePort] from web workers into a Dart
|
|
|
|
/// [StreamChannel].
|
|
|
|
extension PortToChannel on MessagePort {
|
|
|
|
/// Converts this port to a two-way communication channel, exposed as a
|
|
|
|
/// [StreamChannel].
|
|
|
|
///
|
|
|
|
/// This can be used to implement
|
|
|
|
StreamChannel<Object?> channel() {
|
|
|
|
final controller = StreamChannelController();
|
|
|
|
onMessage.map((event) => event.data).pipe(controller.local.sink);
|
|
|
|
controller.local.stream.listen(postMessage, onDone: close);
|
|
|
|
|
|
|
|
return controller.foreign;
|
|
|
|
}
|
|
|
|
}
|