drift icon indicating copy to clipboard operation
drift copied to clipboard

Allow `returning` in batch operations

Open rubenferreira97 opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe. Sometimes I need to get columns that were inserted in a batch insert, like in createReturning. Example: Get generated columns like id, computed columns like createdAt.

Currently bulkCreate returns Future<void>.

Future<void> createArticles(List<ArticleCompanion> articles) async {
  return database.managers.article.bulkCreate(
    (f) => articles,
  );
}

Describe the solution you'd like

  • Change Future<void> bulkCreate(...) to Future<Iterable<PrimaryKeyType>> bulkCreate(...). This might be a slight breaking change but since you can assign Iterable<PrimaryKeyType> to void it should be fine.
  • Add Future<Iterable<ArticleData>> bulkCreateReturning(...).

I don't know the inner batch implementation but I think it should be feasible to implement this.

rubenferreira97 avatar Oct 30 '24 11:10 rubenferreira97

I agree that this would be nice to have :+1: It is possible, but definitely a lot of work since it touches all backends + isolates + web workers for the transport. And then we have to provide the API for both the core Batch as well as the manager APIs.

simolus3 avatar Oct 30 '24 21:10 simolus3