首页 > 解决方案 > 是否有用于 Flutter 的 SQLite 的 NoSQL 替代品?

问题描述

我正在构建一个独立的(没有对 MongoDB 或 Firebase 等的 API 调用)flutter 应用程序,其中数据库管理至关重要。目前,我将它存储为 JSON,但它的效率很低。我不能使用 SQLite,因为数据非常嵌套,事实上,JSON 是存储我的数据的唯一方法。因此,我正在寻找 NoSQL 替代方案。

这是我要存储的数据模型。

lib/book_model.dart


@JsonSerializable()
class Book {
  /// Do not change this. It's a primary key.
  String bookLink;
  String authors = null;
  String thumbnail = null;
  String bookName = null;

  List<Chapter> totalChaptersList = [];

  ///todo: determine datatype
  var currentChapter;

  String summary = null;

  double rating = 0.0;

  List<String> genres = [];
  Book({
    this.bookLink,
    this.authors,
    this.thumbnail,
    this.bookName,
    this.totalChaptersList,
    this.currentChapter,
    this.summary,
    this.rating,
    this.genres,
  });

  Book.generateFromSearchBook(SearchBook searchBook) {
    this.authors = searchBook.authors;
    this.bookLink = searchBook.bookLink;
    this.bookName = searchBook.bookName;
    this.thumbnail = searchBook.thumbnail;
  }

  // @override
  // String toString() {
  //   return "<$bookLink , $authors , $thumbnail , $bookName , $summary , $genres , $rating , $totalChaptersList , $currentChapter>";
  // }

  factory Book.fromJson(Map<String, dynamic> json) => _$BookFromJson(json);
  Map<String, dynamic> toJson() => _$BookToJson(this);
}

@JsonSerializable()
class Chapter {
  String name = null;
  String date = null;
  String chapterLink = null;

  @JsonKey(defaultValue: false)
  bool has_read = false;

  List<Page> pages = [];
  
  Chapter({
    this.name,
    this.date,
    this.chapterLink,
    this.has_read,
    this.pages,
  });

  // @override
  // String toString() {
  //   return "<$name , $date , $chapterLink , $has_read , $pages>";
  // }

  factory Chapter.fromJson(Map<String, dynamic> json) => _$ChapterFromJson(json);
  Map<String, dynamic> toJson() => _$ChapterToJson(this);
}

@JsonSerializable()
class Page {
  String pageLink = null;
  int pageNumber = 0;
  Page({
    this.pageLink,
    this.pageNumber,
  });

  // @override
  // String toString() {
  //   return "<$pageLink , $pageNumber>";
  // }
  factory Page.fromJson(Map<String, dynamic> json) => _$PageFromJson(json);
  Map<String, dynamic> toJson() => _$PageToJson(this);
}

标签: sqliteflutternosql

解决方案


我找到了这两个

  • Hive - Hive 是一个用纯 Dart 编写的轻量级和超快速键值数据库。受 Bitcask 启发。
  • ObjectBox - ObjectBox 是一个在本地存储 Dart 对象的超快速数据库。

推荐阅读