【问题标题】:How to deal with sqlite database versioning in Flutter?如何处理 Flutter 中的 sqlite 数据库版本控制?
【发布时间】:2019-09-19 09:44:39
【问题描述】:

我找到了sqlite 数据库版本控制https://github.com/jgilfelt/android-sqlite-asset-helper,但我在Flutter 中找不到sqflite 数据库版本控制。

我想使用预填充的数据库发布我的应用,但我不知道如何处理数据库的应用升级版本发布。

【问题讨论】:

    标签: flutter versioning sqflite


    【解决方案1】:

    预加载数据 您可能希望在第一次打开时预加载数据库。你可以

    Import an existing SQLite file先检查数据库文件是否存在 在 onCreate 期间填充数据:

    _onCreate(Database db, int version) async {
      // Database is created, create the table
      await db.execute(
        "CREATE TABLE Test (id INTEGER PRIMARY KEY, value TEXT)");
      }
      // populate data
      await db.insert(...);
    }
    
    // Open the database, specifying a version and an onCreate callback
    var db = await openDatabase(path,
        version: 1,
        onCreate: _onCreate);
    

    https://github.com/tekartik/sqflite/blob/master/sqflite/doc/opening_db.md

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-15
      • 2014-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多