keel icon indicating copy to clipboard operation
keel copied to clipboard

feat: function configuration for auto transactions

Open tomfrew opened this issue 5 months ago • 0 comments

We currently wrap all mutation functions in a transaction which gets rolled back if the function throws an error. This is a great default but there are times where you do want to write to the db and also return an error. This PR adds optional configuration to our generated function wrappers which would enable users to control the behaviour of the functions runtime. And then uses this config to control the automatic transaction behaviour

e.g.

MyFunction.config = {
  autoTransaction: false,
};

export default MyFunction(async (ctx, inputs) => {
  // .. do things
});

or for hooks

const hooks: MyFunctionHooks = {
  beforeWrite: async (ctx, inputs, values, record) => {
   // ..do things
  },
};

MyFunction.config = {
  autoTransaction: false,
};

export default MyFunction(hooks);

tomfrew avatar Sep 27 '24 10:09 tomfrew