Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ static SqlTemplate<Map<String, Object>, SqlResult<Void>> forUpdate(SqlClient cli
return new SqlTemplateImpl<>(client, sqlTemplate, query -> query.collecting(SqlTemplateImpl.NULL_COLLECTOR), sqlTemplate::mapTuple);
}


/**
* @return the computed SQL for this template
*/
String getSql();

/**
* Set a parameters user defined mapping function.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

import io.vertx.core.Future;
import io.vertx.core.json.JsonObject;
import io.vertx.sqlclient.PreparedQuery;
import io.vertx.sqlclient.Row;
import io.vertx.sqlclient.RowSet;
import io.vertx.sqlclient.SqlClient;
import io.vertx.sqlclient.SqlResult;
import io.vertx.sqlclient.Tuple;
import io.vertx.sqlclient.*;
import io.vertx.sqlclient.templates.RowMapper;
import io.vertx.sqlclient.templates.TupleMapper;

Expand Down Expand Up @@ -37,6 +32,11 @@ public SqlTemplateImpl(SqlClient client,
this.tupleMapper = tupleMapper;
}

@Override
public String getSql() {
return sqlTemplate.getSql();
}

@Override
public <T> io.vertx.sqlclient.templates.SqlTemplate<T, R> mapFrom(TupleMapper<T> mapper) {
return new SqlTemplateImpl<>(client, sqlTemplate, queryMapper, params -> mapper.map(sqlTemplate, sqlTemplate.numberOfParams(), params));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ protected <P, T, V> void testGet(TestContext ctx,
Function<T, V> extractor,
String column) {
Async async = ctx.async();
String query = "SELECT %s :: %s \"%s\"";
SqlTemplate<P, RowSet<T>> template = SqlTemplate
.forQuery(connection, "SELECT #{" + paramName + "} :: " + sqlType + " \"" + column + "\"")
.forQuery(connection, String.format(query, "#{" + paramName + "}", sqlType, column))
.mapFrom(paramsMapper)
.mapTo(rowMapper);
ctx.assertEquals(String.format(query, "$1", sqlType, column), template.getSql());
template
.execute(params)
.onComplete(ctx.asyncAssertSuccess(result -> {
Expand Down