Class SqlTemplate<I,R>
- All Implemented Interfaces:
RxDelegate
SQL templates are useful for interacting with a relational database.
SQL templates execute queries using named instead of positional parameters. Query execution is parameterized
by a map of string to objects instead of a Tuple. The default source of parameters is a
simple map, a user defined mapping can be used instead given it maps the source to such a map.
SQL template default results are , a user defined mapping can be used instead, mapping the result set to a of the mapped type.
NOTE: This class has been automatically generated from the original non RX-ified interface using Vert.x codegen.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanio.reactivex.rxjava3.core.Single<R>Execute the query with theparametersio.reactivex.rxjava3.core.Single<R>executeBatch(List<I> batch) Execute a batch query with thebatch.Create an SQL template for query purpose consuming map parameters and returning .Create an SQL template for query purpose consuming map parameters and returning void.inthashCode()<T> SqlTemplate<T,R> mapFrom(TupleMapper<T> mapper) Set a parameters user defined mapping function.<T> SqlTemplate<T,R> Set a parameters user defined class mapping.<U> SqlTemplate<I,RowSet<U>> Set a row user defined mapping function.<U> SqlTemplate<I,RowSet<U>> Set a row user defined mapping function.static <I,R> SqlTemplate<I, R> newInstance(SqlTemplate arg) static <I,R> SqlTemplate<I, R> newInstance(SqlTemplate arg, TypeArg<I> __typeArg_I, TypeArg<R> __typeArg_R) io.reactivex.rxjava3.core.Single<R>Execute the query with theparametersio.reactivex.rxjava3.core.Single<R>rxExecuteBatch(List<I> batch) Execute a batch query with thebatch.sql()toString()withClient(SqlClient client) Returns a new template, using the specifiedclient.
-
Field Details
-
__TYPE_ARG
-
__typeArg_0
-
__typeArg_1
-
-
Constructor Details
-
SqlTemplate
-
SqlTemplate
-
-
Method Details
-
toString
-
equals
-
hashCode
public int hashCode() -
getDelegate
- Specified by:
getDelegatein interfaceRxDelegate
-
forQuery
public static SqlTemplate<Map<String,Object>, forQueryRowSet<Row>> (SqlClient client, String template) Create an SQL template for query purpose consuming map parameters and returning .- Parameters:
client- the wrapped SQL clienttemplate- the template query string- Returns:
- the template
-
forUpdate
public static SqlTemplate<Map<String,Object>, forUpdateSqlResult<Void>> (SqlClient client, String template) Create an SQL template for query purpose consuming map parameters and returning void.- Parameters:
client- the wrapped SQL clienttemplate- the template update string- Returns:
- the template
-
sql
- Returns:
- the computed SQL for this template
-
mapFrom
Set a parameters user defined mapping function.At query execution, the
mapperis called to map the parameters object to aTuplethat configures the prepared query.- Parameters:
mapper- the mapping function- Returns:
- a new template
-
mapFrom
Set a parameters user defined class mapping.At query execution, the parameters object is is mapped to a
Map<String, Object>that configures the prepared query.This feature relies on
JsonObjectfeature. This likely requires to use Jackson databind in the project.- Parameters:
type- the mapping type- Returns:
- a new template
-
mapTo
Set a row user defined mapping function.When the query execution completes, the
mapperfunction is called to map the resulting rows to objects.- Parameters:
mapper- the mapping function- Returns:
- a new template
-
mapTo
Set a row user defined mapping function.When the query execution completes, resulting rows are mapped to
typeinstances.This feature relies on
JsonObjectfeature. This likely requires to use Jackson databind in the project.- Parameters:
type- the mapping type- Returns:
- a new template
-
withClient
Returns a new template, using the specifiedclient.This method does not compute the template query again, so it can be useful to execute a template on a specific
SqlConnection. For example, after starting a transaction:// Typically stored as a verticle field // So that heavy computation of the template happens once SqlTemplate<Map<String, Object>, RowSet
> template = SqlTemplate .forQuery(pool, "SELECT id, randomnumber FROM tmp_world") .mapTo(World.class); // Executing the template inside a transaction Future<RowSet > future = pool.withTransaction(conn -> template.withClient(conn).execute(Map.of())); - Parameters:
client- the client that will execute requests- Returns:
- a new template
-
execute
Execute the query with theparameters- Parameters:
params- the query parameters- Returns:
- a future notified with the result
-
rxExecute
Execute the query with theparameters- Parameters:
params- the query parameters- Returns:
- a future notified with the result
-
executeBatch
Execute a batch query with thebatch.Each item in the batch is mapped to a tuple.
- Parameters:
batch- the batch- Returns:
- a future notified with the result
-
rxExecuteBatch
Execute a batch query with thebatch.Each item in the batch is mapped to a tuple.
- Parameters:
batch- the batch- Returns:
- a future notified with the result
-
newInstance
-
newInstance
public static <I,R> SqlTemplate<I,R> newInstance(SqlTemplate arg, TypeArg<I> __typeArg_I, TypeArg<R> __typeArg_R)
-