Comments (5)
Be careful with that, I think it would update all tasks and apply the finished: false
column to every row. If the task has a non-null id
then the copyWith
/replace
call should work.
You could also do (update(tasks)..whereSamePrimaryKey(task)).write(TasksCompanion(finished: state))
- but again, only if task.id
is not null.
from drift.
The only null value that I see during debug is the id(because we do copyWith)
So to be sure, you're calling replace
with a Task
object that has its id
field set to null
? That would explain the error, but I don't think drift can do much against that (except giving a better error message). Tasks are identified by their id and we need to know which task to replace, but we can't do that if id
is null.
from drift.
Thanks for the report! Do you have an empty primary key? Could you post the definition of the Tasks
table as well?
from drift.
I slightly updated the table names but the structure is basically the same
During task.copyWith
the original task has the id
import 'package:json_annotation/json_annotation.dart' as ja;
@UseRowClass(Task)
class Tasks extends Table {
IntColumn get id => integer().autoIncrement()();
IntColumn get orderId => integer().references(Orders, #id, onDelete: KeyAction.cascade)();
BoolColumn get finished => boolean().withDefault(const Constant(false))();
}
@ja.JsonSerializable()
class Task implements Insertable<Task> {
...
The "tasks" are fetched from api and saved like this
final Set<TasksCompanion> tasksCompanions;
tasks.forEach((taskJson) {
tasksCompanions.add(Task.fromJson({
'order_id': orderJson['id'],
'finished': false
}).toCompanion(true));
});
... call daos
I checked the state. The items are being saved with no issues
from drift.
You're right. This works. Thank you!
Future<void> toggleFinish(Task task, bool state) {
return update(tasks)
.write(TasksCompanion(finished: state));
}
edit: oh, I meant where task, passing the existing task -___-
Another option is to search through other fields. update.where.write
from drift.
Related Issues (20)
- Converting database keys in toJson from camelCase to snake_case HOT 1
- LazyDatabase is imposible to execute queries when reopen HOT 1
- flutter web unable to build HOT 1
- No `SqliteException` thrown if when fetching data from non existent column in test mode HOT 4
- Can't compile to wasm HOT 1
- [web] TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm' HOT 1
- SqliteException(1): while preparing a statement, unrecognized token: "@" HOT 3
- Database can no longer be mocked with new manager API HOT 10
- [Documentation] Insufficient documentation and examples on complex migration HOT 1
- Ability to mark foreign key constraint as deferrable HOT 1
- Schema verifier fails in setting DatabaseConfig.doubleQuotedStringLiterals HOT 4
- Flutter not resolving
- database is locked error with WAL journal mode HOT 4
- Option to run a few queries sequentially HOT 3
- Code generation creates database table with wrong type HOT 9
- Drift generator doesn't strip custom row class from SQL HOT 1
- Primary Key not required in companion insert HOT 1
- Issue with generated code: database.g.dart file HOT 19
- Select int64 return type HOT 2
- Start a select with the Dart API without specifiying a table
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drift.