Skip to content

Commit

Permalink
测试更新时计算
Browse files Browse the repository at this point in the history
貌似只能支持数字计算,无法构造字符串,REPLCACE之类也用不了,
  • Loading branch information
AoEiuV020 committed Apr 20, 2024
1 parent 6b673aa commit a0d82b1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"cSpell.words": [
"AUTOINCREMENT",
"Insertable",
"sublist"
]
}
23 changes: 16 additions & 7 deletions lib/src/view/database_operator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class _DatabaseOperatorState extends State<DatabaseOperator> {
final database = widget.database;
final list = await database.select(database.todoItems).get();
setState(() {
items.clear();
items.addAll(list);
});
}
Expand All @@ -36,16 +37,22 @@ class _DatabaseOperatorState extends State<DatabaseOperator> {
final item = items[i];
final id = item.id;
final title = 'reset $i';
final content = 'content $i';
await (database.update(database.todoItems)
..where((tbl) => tbl.id.equals(id)))
.write(TodoItemsCompanion(
title: drift.Value(title),
content: drift.Value(content),
));
final content = 'old.category: ${item.category}';
final category = (item.category ?? 0) + i;
final newItem =
TodoItem(id: id, title: title, content: content, category: category);
await database.into(database.todoItems).insert(newItem,
onConflict: drift.DoUpdate(
(old) => TodoItemsCompanion.custom(
title: drift.Constant(title),
content: drift.Constant(content),
category: old.category + drift.Constant(i),
),
));
items[i] = item.copyWith(
title: title,
content: content,
category: drift.Value(category),
);
}
setState(() {});
Expand All @@ -57,11 +64,13 @@ class _DatabaseOperatorState extends State<DatabaseOperator> {
for (var i = 0; i < count; i++) {
final title = 'title $i';
final content = 'content $i';
final category = i;
final id = await database
.into(database.todoItems)
.insert(TodoItemsCompanion.insert(
title: title,
content: content,
category: drift.Value(category),
));
final item = TodoItem(id: id, title: title, content: content);
setState(() {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/view/todo_item_line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TodoItemLine extends StatelessWidget {
return Column(
children: [
Text("${item.id}: ${item.title}"),
Text("content: ${item.content}"),
Text("${item.category} ${item.content}"),
],
);
}
Expand Down

0 comments on commit a0d82b1

Please sign in to comment.