drift
drift copied to clipboard
Allow `returning` in batch operations
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(...)toFuture<Iterable<PrimaryKeyType>> bulkCreate(...). This might be a slight breaking change but since you can assignIterable<PrimaryKeyType>tovoidit 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.
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.