パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v2.0.1

simple_database

SharedPreferences Flutterパッケージのためのシンプルで軽量なラッパー。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
39
いいね数
6
Pub ポイント
140

パッケージをインストール

flutter pub add simple_database

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

FlutterのSharedPreferencesをラップする軽量で使いやすいラッパーで、Flutterアプリケーションにおける永続的なデータストレージを簡素化することを目的としています。保存、取得、キー値ペアの削除といった一般的な操作を最小限のボイラープレートで抽象化しています。完全なデータベースの複雑さなしに基本的なローカルストレージが必要な小規模アプリに最適です。このパッケージはクロスプラットフォームであり、Android、iOS、Web、macOS、Windows、Linuxをサポートしており、さまざまなデプロイシナリオに対応可能です。

用途

  • ユーザー設定の保存
  • セッション間でアプリの状態を保存する
  • 少量のデータをキャッシュする
  • 簡単な設定の管理
  • ログイントークンの永続化
  • ユーザー活動の追跡

主な機能

  • 最小API表面
  • 自動タイプシリアル化
  • クロスプラットフォーム互換性
  • 簡単なセットアップ
  • 軽量なフィートプリント
  • エラー処理

適している対象

  • 初心者のFlutter開発者
  • 小規模から中規模のアプリ
  • プロトタイプとMVP
  • 基本的な永続性要件を持つアプリ
  • 複雑なデータベース設定を回避するプロジェクト

注意事項

  • 大規模なデータセットには適していません
  • クエリやインデックス作成のサポートなし
  • キー値ストレージに限定
  • デフォルトではデータは暗号化されていません
  • 高周波の書き込みによりパフォーマンスが低下する
  • 重要なでない、小規模なデータに最適

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Simple Database

CI codecov

A simple lightweight wrapper for the SharedPreferences Flutter package. Simple Database provides an abstraction layer for storing objects instead of key, value pairs. This makes it very easy to get a quick local storage solution up and running.

GitHub

Please feel free to contribute

Usage

Please add simple_database as a dependency in your pubspec.yaml file

No Setup Primative Storage

You can easily setup a database of primitive types just by assigning it a name, Simple Database will init the DB if it has not been created yet on the phone for you.

void main() async {
    SimpleDatabase names = SimpleDatabase(name: 'names');

    await names.add('Bob');
    await names.add('Doug');

    for (var name in await names.getAllType<String>()) {
      print(name);
    }
}

Mixed Types

You can use a single database that stores multiple primitive types and then specify what type you want from the database.

void main() async {
    SimpleDatabase names = SimpleDatabase(name: 'names');

    await names.add('Bob');
    await names.add(150)
    await names.add('Doug');
  
    //Print out all strings in the db
    for (var name in await names.getAllType<String>()) {
      print(name);
    }
  
    //Print out at an index, with a type
    var number = await names.getAtType<int>(1);
    print(number);
}

Non-Primitive object storage

You can store your own objects you have created easily just by implementing 2 functions in the class. toJson and fromJson. You will need to pass the fromJson function to the constructor of SimpleDatabase if you want it to rebuild the json into your object. You do not need this, it will just return a hash map with the values from your object if the function is not provided.


class SimpleClass {
  final int age;
  final String name;
  final double height;
  final bool gender;

  SimpleClass(this.age, this.name, this.height, this.gender);

  //Implement fromJson - Required
  SimpleClass.fromJson(Map<String, dynamic> json) : age = json['age'], name = json['name'], height = json['height'], gender = json['gender'];

  //Implement toJson - Required
  Map<String, dynamic> toJson() => {
    'age': age,
    'name' : name,
    'height' : height,
    'gender' : gender,
  };
}

void main() async {
    SimpleDatabase classDB = SimpleDatabase(name: 'class', fromJson: (fromJson) => SimpleClass.fromJson(fromJson));

    SimpleClass john = SimpleClass(18, 'John', 5.2, true);  

    await classDB.add(john);

    SimpleClass person = await classDB.getAtType<SimpleClass>(0);
    print(person.name);
}

TODO:

  • Built in encryption of stored json strings
  • Better documentation

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。