[英]Flutter: How to work with multiple tables in Sqflite?
在 Sqflite 中使用多个表的推荐方法是什么。 我应该使用一个数据库助手来管理一个 .db 文件中的所有表。 或者我应该为每个表创建单独的数据库助手。
我有 8 个表要存储在数据库中。 所有这 8 个表都是在不同的区域中创建的,这意味着我不希望它们在一个区域中创建。 该应用程序正在为商店创建以管理所有会计。 所以有一个供应商表,有一个村庄表等等。 此外,此应用程序不会连接到网络。 这是一个仅限离线的应用程序。 那么,在这种情况下哪种方法最好?
对我来说,我有三个 DB 表,和许多其他应用程序开发人员一样,我只是为每个表创建一个全新的 .db 文件。
但是,您可以组合db.execute
调用并创建一个可以处理许多表的管理器。
在一个文件中创建多个表的示例:(来源: 如何在 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 。 它在一个数据库文件中使用多个表,因此您可以获得它如何操作的示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.