manifold-systems / manifold

Manifold is a Java compiler plugin, its features include Metaprogramming, Properties, Extension Methods, Operator Overloading, Templates, a Preprocessor, and more.
http://manifold.systems/
Apache License 2.0
2.42k stars 125 forks source link

manifold-sql: support batched SQL #606

Closed rsmckinney closed 4 months ago

rsmckinney commented 4 months ago

Currently, we have the ability to use arbitrary SQL commands via addSqlChange():

MyDb.addSqlChange(ctx -> {
  for(int i = 0; i < N; i++) {
    "[.sql/] insert into country (country) values (:value)".execute( ctx, "name" + i );
  }
});

This is nice, however in this case it is more performant to batch the insert commands in one call.

Proposal

Add a batch counterpart to addSqlChange, say addBatchChange.

MyDb.addBatchChange(ctx -> {
  for(int i = 0; i < N; i++) {
    "[.sql/] insert into country (country) values (:value)".execute( ctx, "name" + i );
  }
});

Basically, make it so one can easily change any addSqlChange to an addBatchChange where SQL calls are automatically batched where possible.

Since there are two kinds of batch modes: parameterized vs unparameterized. A resulting batch will consist of one batch for all non-parameterized commands and N batches corresponding with parameterized commands.

Note, although entity CRUD calls may be used within addSqlChange they are not amenable to batching, therefor SQL commands generated from those calls will remain unchanged inside addBatchChange.

rsmckinney commented 4 months ago

Feature available with release 2024.1.20