Skip to content

Commit

Permalink
Add Params interface to carry binding
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMarkyMarkus committed Sep 20, 2023
1 parent 5dc0388 commit 9bf751a
Show file tree
Hide file tree
Showing 5 changed files with 294 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;

import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.Parameter;
import io.r2dbc.spi.Readable;
import io.r2dbc.spi.Result;
import io.r2dbc.spi.Row;
Expand Down Expand Up @@ -210,6 +212,13 @@ interface GenericExecuteSpec {
*/
GenericExecuteSpec bindProperties(Object source);

/**
* Bind values from the given mapping function.
* @param paramsFunction a function that maps from {@link Params} to {@link Params} with new bindings
* @since 6.1
*/
GenericExecuteSpec bind(UnaryOperator<Params> paramsFunction);

/**
* Add the given filter to the end of the filter chain.
* <p>Filter functions are typically used to invoke methods on the Statement
Expand Down Expand Up @@ -300,4 +309,51 @@ default GenericExecuteSpec filter(Function<? super Statement, ? extends Statemen
Mono<Void> then();
}

/**
* Interface that defines common functionality for parameter binding.
*/
interface Params {
/**
* See {@link GenericExecuteSpec#bind(String, Object)}.
*/
Params bind(String name, Object value);

/**
* See {@link GenericExecuteSpec#bind(int, Object)}.
*/
Params bind(int index, Object value);

/**
* See {@link GenericExecuteSpec#bindNull(String, Class)}.
*/
Params bindNull(String name, Class<?> type);

/**
* See {@link GenericExecuteSpec#bind(int, Object)}.
*/
Params bindNull(int index, Class<?> type);

/**
* See {@link GenericExecuteSpec#bindValues(Map)}.
*/
Params bindValues(Map<String, ?> source);

/**
* See {@link GenericExecuteSpec#bindProperties(Object)}.
*/
Params bindProperties(Object source);

/**
* Get bindings by index.
* @return index based params
*/
Map<Integer, Parameter> byIndex();

/**
* Get bindings by name.
* @return name based params
*/
Map<String, Parameter> byName();
}

}
Loading

0 comments on commit 9bf751a

Please sign in to comment.