本文介绍了在Sqflite中插入多个记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在sqflite
中快速插入多个记录?标准的快速方法是:
How to insert quickly multiple records in sqflite
? The standard quickly method is:
await database.insert(table, object.toMap())
但是我不认为插入记录与循环一对一是一个好主意.或者我可以在交易中插入所有列表?
But I don't think that insert record one to one with a cycle is a good idea.Or I can insert all list with a transaction?
推荐答案
正如我在评论中提到的,您可以使用Batch
.这是示例.
As I mentioned in the comment, you can use Batch
. Here is the sample.
Batch batch = db.batch();
batch.insert('Test', {'name': 'item'});
batch.update('Test', {'name': 'new_item'}, where: 'name = ?', whereArgs: ['item']);
batch.delete('Test', where: 'name = ?', whereArgs: ['item']);
现在,如果您要查找结果(这会占用一些内存),请使用
Now if you are looking for result (it will cost you some memory), you use
results = await batch.commit();
如果您正在寻找快速的性能,只需忽略结果并使用
And if you are looking for fast performance, just ignore the result and use
await batch.commit(noResult: true);
这篇关于在Sqflite中插入多个记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!