Open tejainece opened 6 years ago
@jaumard Have tested all different field types: https://github.com/jaguar-orm/sqflite/blob/master/lib/post.dart
Cool !! Are you able to read them back correctly ? Because on my PR I guess it was for the save, but once you read back the values bool and dateTime need to be converted back from integer 0/1 (maybe automatic this one) and text to datetime
Yes. I have added readback capability using parseValue
method on Adapter
.
Try the example project.
I'll for sure :) but can't right now and I was curious :D thanks !
@tejainece I'm going to test right now, but I just saw this on the doc of sqflit https://github.com/tekartik/sqflite/blob/master/doc/opening_db.md interesting part is that only one database can be opened (all other will have database locked) it mean that on the Adapter we can't pass only the path, we have to pass the full database object as it has to be a singleton. With the current implementation only one bean will work and all others will have lock issue
Made a PR with my fix to have it working on my side https://github.com/jaguar-orm/sqflite/pull/1
@jaumard Agree, we have to pass the full database path.
Same adapter can be shared with all beans, if it is the same database.
I tried a simple one to one relation but it doesn't seems to work :(
Here is the generated insert method:
Future<Null> insert(Post model, {bool cascade: false}) async {
final Insert insert = inserter.setMany(toSetColumns(model));
await execInsert(insert);
if (cascade) {
Post newModel;
if (model.item != null) {
newModel ??= await find(model.id);
itemBean.associatePost(model.item, newModel);
await itemBean.insert(model.item);
}
}
}
Why returning null now and not the id ? For me the correct generated method should be:
Future<dynamic> insert(Post model, {bool cascade: false}) async {
final Insert insert = inserter.setMany(toSetColumns(model));
var id = await execInsert(insert);
if (cascade) {
Post newModel;
if (model.item != null) {
newModel ??= await find(id);
itemBean.associatePost(model.item, newModel);
await itemBean.insert(model.item);
}
}
return id;
}
Because in case of auto increment id, the model.id will be null on the current behavior.
Also auto increment is not working, apparently some mistake in the sql query. I'll try to check why but I'll put all the problem I have here to not forget something
@jaumard Did you tag the primary key field with @PrimaryKey()
annotation. It will return the new id, if you tag the field.
@tejainece yes I use your repo example and you put the @PrimaryKey()
annotation on it
If you want to check I put everything here https://github.com/jaumard/sqflite/tree/bugfix/fix_example
Fixing.
Could you send a pull request of your changes?