Comments (7)
You can use Future<int>
or Future<List<int>>
as a return type for @insert
DAO functions, e.g.
@insert
Future<int> insertPerson(Person person);
will return a primary id which was generated and used by sqlite.
Of course, this will only work if your primary key is of type integer, but I think that only integer primary keys can be generated anyway. The id
(or whatever you named it) field of those Person
objects will not have changed, you would have to do that yourself if you want.
See also the README
from floor.
In the case of @update
and @delete
it will return the count of changed rows, not the id. This last inserted ID
in this ticket only applies to @insert
. And as the (admittedly short) issue description says is
Investigate what Room returns on update and delete and decide if support these as well.
And this is (at least from my PoV) the amount of rows that were changed by the operation, just like the titles of the referenced PRs indicate.
If you want the id of your updated row(s), look inside the id field of the Entity you provided to the update function, as this will not be changed(in the db and in your app) by either update nor delete operations.
from floor.
This feature is already available in last version 0.12.0? If yes, how can I perform it?
from floor.
In the previous version if I am not wrong the returned int value was 0 or 1 (true or false), just to represent if the insert/update were done/committed without errors. Now it's pretty better providing the accuracy ID information. But seems to be an issue in @update annotation.
In @update the floor API seems to returning always 1 instead of the ID. In @insert it's Ok returning the correct Id.
#personDao.dart
@update
Future updatePerson(Person person);
#instantiating the dao
id = personDao.updatePerson(_person);
In that case, the id is always == 1, instead of the committed _person.id
from floor.
@mqus ok, it was very clear. Really this way similar to Room got better, thks!
from floor.
And honestly, if you had read the README link I gave you, this would have been obvious:
@update marks a method as an update method. When using the capitalized @update you can specify a conflict strategy. Else it just defaults to aborting the update. These methods can return a Future of either void or int.
void return nothing
int return number of changed rows
@delete marks a method as a deletion method. These methods can return a Future of either void or int.
void return nothing
int return number of deleted rows
from floor.
Yeap indeed. I didn't understand correctly. It's very clear in docs!
from floor.
Related Issues (20)
- Improve FTS documentation and add some examples
- Not supported on Flutter Web HOT 1
- dependecy conflict with riverpod_lint 2.3.3 HOT 2
- Dumplicate field name when entity implement form abstract class HOT 1
- duplicate field name when entity implement form abstract class
- Unhandled Exception: type 'Null' is not a subtype of type 'double' in type cast HOT 1
- This exception cannot be executed on the entire floor library
- trying to get a SUM of a field with floor. HOT 1
- Custom Database File Path HOT 1
- sqlite wal HOT 1
- How to update a List of an object as field of entity into table in Floor
- How add rawQuery added ?? HOT 2
- Are there any plans to adapt HarmonyOS HOT 4
- Imports collision HOT 1
- #802 still an issue. any help?
- Casting to double might not work; HOT 1
- dependencies issue HOT 5
- Invalid query (failing to parse) does not throw an error
- onCreate callback is not being called, "tbl not found" exception
- How to select with like ??? HOT 3
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 floor.