Flutter:如何在Sqflite中使用多个表?

问题描述 投票:0回答:1

在Sqflite中使用多个表的推荐方式是什么。我是否应该使用一个数据库助手来管理一个.db文件中的所有表。还是应该为每个表创建单独的数据库助手。

我有8个表要存储在数据库中。所有这8个表都是在不同的区域创建的,这意味着我不希望它们被一次创建。正在为商店创建该应用程序以管理所有会计。因此,有一个供应商表,有一个乡村表,依此类推。此外,此应用程序将无法连接到网络。这是仅离线应用程序。因此,在这种情况下哪种方法最好?

database sqlite flutter
1个回答
0
投票

对我来说,我有三个数据库表,就像许多其他应用程序开发人员一样,我只是为每个表创建一个全新的.db文件。

但是,您可以只组合db.execute调用并创建一个可以处理许多表的管理器。

在一个文件中创建多个表的示例:(信用:How to create multiple tables in a database in sqflite?

await db.execute('''
  create table $reminderTable (
    $columnReminderId integer primary key autoincrement,
    $columnReminderCarId integer not null,
    $columnReminderName text not null,
    $columnReminderNotifyMileage integer not null,
    $columnReminderEndMileage integer not null
   )''');
await db.execute('''
   create table $carTable (
    $columnCarId integer primary key autoincrement,
    $columnCarTitle text not null
   )''');

[我还将看一下这篇文章:https://steemit.com/programming/@tstieff/using-sqflite-in-your-flutter-applicaiton-effectively。它在一个数据库文件中使用多个表,因此您可以获取有关其运行方式的示例。

© www.soinside.com 2019 - 2024. All rights reserved.