Class SqlTemplate<I,R>
- All Implemented Interfaces:
MutinyDelegate
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 Row, a user defined mapping can be used instead, mapping the
result set Row to a RowSet of the mapped type.
NOTE: This class has been automatically generated from the original non Mutiny-ified interface.
- See Also:
-
SqlTemplate
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSqlTemplate(io.vertx.sqlclient.templates.SqlTemplate<I, R> delegate) Create a new instance ofSqlTemplatedelegating to the given (non-null) instance ofSqlTemplate.SqlTemplate(io.vertx.sqlclient.templates.SqlTemplate<I, R> delegate, TypeArg<I> typeArg_0, TypeArg<R> typeArg_1) -
Method Summary
Modifier and TypeMethodDescriptionbooleanio.smallrye.mutiny.Uni<R>Execute the query with theparametersexecuteAndAwait(I params) Execute the query with theparametersexecuteAndForget(I params) Execute the query with theparametersio.smallrye.mutiny.Uni<R>executeBatch(List<I> batch) Execute a batch query with thebatch.executeBatchAndAwait(List<I> batch) Execute a batch query with thebatch.executeBatchAndForget(List<I> batch) Execute a batch query with thebatch.Create an SQL template for query purpose consuming map parameters and returningRow.Create an SQL template for query purpose consuming map parameters and returning void.Get the delegate instance.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(io.vertx.sqlclient.templates.SqlTemplate<I, R> delegate) Creates a new instance of theSqlTemplate.static <I,R> SqlTemplate<I, R> newInstance(io.vertx.sqlclient.templates.SqlTemplate<I, R> delegate, TypeArg<I> typeArg_0, TypeArg<R> typeArg_1) Creates a new instance of theSqlTemplate.sql()toString()withClient(SqlClient client) Returns a new template, using the specifiedclient.
-
Field Details
-
__TYPE_ARG
-
__typeArg_0
-
__typeArg_1
-
-
Constructor Details
-
SqlTemplate
Create a new instance ofSqlTemplatedelegating to the given (non-null) instance ofSqlTemplate. -
SqlTemplate
-
SqlTemplate
-
-
Method Details
-
getDelegate
Get the delegate instance.This method returns the instance on which this shim is delegating the calls. And so, give you access to the bare API.
- Specified by:
getDelegatein interfaceMutinyDelegate- Returns:
- the delegate instance
-
execute
Execute the query with theparametersUnlike the bare Vert.x variant, this method returns a
Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.Don't forget to subscribe on it to trigger the operation.
- Parameters:
params- the query parameters- Returns:
- A
Unirepresenting the asynchronous result of this operation. - See Also:
-
io.vertx.sqlclient.templates.SqlTemplate#execute(I)
-
executeAndAwait
Execute the query with theparametersUnlike the bare Vert.x variant, this method returns a
SqlTemplate. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in aRuntimeException).- Parameters:
params- the query parameters- Returns:
- The operation result
- See Also:
-
io.vertx.sqlclient.templates.SqlTemplate#execute(I)
-
executeAndForget
Execute the query with theparametersUnlike the bare Vert.x variant, this method ignores the
SqlTemplateresult or any failure.- Parameters:
params- the query parameters- Returns:
- The current instance to chain operations if needed.
- See Also:
-
io.vertx.sqlclient.templates.SqlTemplate#execute(I)
-
executeBatch
Execute a batch query with thebatch.Each item in the batch is mapped to a tuple.
Unlike the bare Vert.x variant, this method returns a
Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.Don't forget to subscribe on it to trigger the operation.
- Parameters:
batch- the batch- Returns:
- A
Unirepresenting the asynchronous result of this operation. - See Also:
-
SqlTemplate.executeBatch(List)
-
executeBatchAndAwait
Execute a batch query with thebatch.Each item in the batch is mapped to a tuple.
Unlike the bare Vert.x variant, this method returns a
SqlTemplate. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in aRuntimeException).- Parameters:
batch- the batch- Returns:
- The operation result
- See Also:
-
SqlTemplate.executeBatch(List)
-
executeBatchAndForget
Execute a batch query with thebatch.Each item in the batch is mapped to a tuple.
Unlike the bare Vert.x variant, this method ignores the
SqlTemplateresult or any failure.- Parameters:
batch- the batch- Returns:
- The current instance to chain operations if needed.
- See Also:
-
SqlTemplate.executeBatch(List)
-
forQuery
public static SqlTemplate<Map<String,Object>, forQueryRowSet<Row>> (SqlClient client, String template) Create an SQL template for query purpose consuming map parameters and returningRow.- 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
JsonObject.mapFrom(java.lang.Object)feature. 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
JsonObject.mapFrom(java.lang.Object)feature. 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
-
newInstance
public static <I,R> SqlTemplate<I,R> newInstance(io.vertx.sqlclient.templates.SqlTemplate<I, R> delegate) Creates a new instance of theSqlTemplate. -
newInstance
public static <I,R> SqlTemplate<I,R> newInstance(io.vertx.sqlclient.templates.SqlTemplate<I, R> delegate, TypeArg<I> typeArg_0, TypeArg<R> typeArg_1) Creates a new instance of theSqlTemplate. -
hashCode
public int hashCode() -
equals
-
toString
-