패키지, 저장소 및 앱 카테고리 검색

패키지 상세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 표면
  • 자동 유형 직렬화
  • 크로스 플랫폼 호환성
  • 간단한 설정
  • 경량 피트프린트
  • 오류 처리

적합한 대상

  • 초보자 플러터 개발자
  • 작은에서 중간 규모의 앱
  • 프로토타입 및 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 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.