搜尋套件、儲存庫與 APP 分類

套件詳情v0.3.0

sqflite_migration

一個用於啟用 SQLite 資料庫遷移的程式庫,使用 sqflite 插件。

AndroidiOSmacOS
近 30 天下載
2520
喜歡數
23
Pub 分數
155

安裝套件

flutter pub add sqflite_migration

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

sqflite_migration 是一個 Flutter 套件,透過 sqflite 插件簡化 SQLite 資料庫的遷移。該工具提供一種結構化的方法來管理隨時間變化的資料庫模式,確保應用程式更新期間的資料完整性。該套件允許開發者定義遷移腳本,在資料庫版本變更時自動執行,從而簡化本地資料庫的版本控制。它與 sqflite 完全整合,並支援 Android、iOS 和 macOS 平台。

適用情境

  • 管理本地 SQLite 資料庫中的架構變更
  • 在應用程式更新期間自動升級資料庫
  • 確保跨應用版本的向後相容性
  • 處理遷移期間的複雜數據轉換
  • 支援多步驟遷移工作流程

主要特色

  • 版本化遷移腳本
  • 資料庫開啟時自動執行遷移
  • 用於定義遷移步驟的簡單 API
  • 與 sqflite 插件的相容性
  • 跨平台支援(Android、iOS、macOS)

適合對象

  • 需要持久本地數據存儲的應用程式
  • 具有不斷演變的資料庫模式的專案
  • 開發人員手動管理資料庫版本控制
  • 需要可靠遷移模式的團隊
  • 具有離線優先架構的 Flutter 應用

使用建議

  • 需要手動設定遷移檔案
  • 依賴於 sqflite 插件
  • 遷移邏輯必須具有冪等性
  • 無內建回滾機制
  • 有限的錯誤處理,僅限基本記錄

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Build Status codecov

Migrate your mobile sqlite database

Library to manage sqlite db migrations using sqflite plugin.

Getting Started

import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
import 'package:sqflite_migration/sqflite_migration.dart';

final initialScript = [
  '''
create table _todo_list (
  id integer primary key autoincrement,
  alias text not null
  )
''',
  '''
create table _task (
  id integer primary key autoincrement,
  description text,
  todo_list_id integer not null,
  CONSTRAINT fk_todo_lists
    FOREIGN KEY (todo_list_id)
    REFERENCES _todo_list(id)
);
'''
];

final migrations = [
  '''
  alter table _task add column done integer default 0;
  '''
];

final config = MigrationConfig(initializationScript: initialScript, migrationScripts: migrations);

Future<Database> open() async {
 final databasesPath = await getDatabasesPath();
 final path = join(databasesPath, 'test.db');
 
 return await openDatabaseWithMigration(path, config);
}

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。