fake_no_sql_database.dart 1 KB
Newer Older
kevin's avatar
kevin committed
1 2
import 'dart:async';

kevin's avatar
kevin committed
3
import 'package:database_interface/database_interface.dart';
kevin's avatar
kevin committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

class FakeCollection implements CollectionInterface {
  @override
  Future<void> delete(Map<String, dynamic> selector) async {}

  @override
  Future<void> drop() async {}

  @override
  Stream<Map<String, dynamic>> find([Map<String, dynamic> selector]) =>
      const Stream.empty();

  @override
  Future<Map<String, dynamic>> findOne(Map<String, dynamic> selector) async =>
      null;

  @override
  Future<void> insert(Map<String, dynamic> document) async {}

  @override
  Future<void> update(
      Map<String, dynamic> selector, Map<String, dynamic> document) async {}
}

28
class FakeNoSqlDatabase implements DatabaseInterface<CollectionInterface> {
kevin's avatar
kevin committed
29 30 31 32 33 34
  bool _isOpen = false;

  @override
  bool get isOpen => _isOpen;

  @override
kevin's avatar
kevin committed
35
  Future<void> close() async {
kevin's avatar
kevin committed
36 37 38 39
    _isOpen = false;
  }

  @override
kevin's avatar
kevin committed
40
  CollectionInterface collection(String name) => FakeCollection();
kevin's avatar
kevin committed
41 42

  @override
kevin's avatar
kevin committed
43
  Future<void> open() async {
kevin's avatar
kevin committed
44 45 46
    _isOpen = true;
  }
}