== Using connections

When you need to execute sequential queries (without a transaction), you can create a new connection
or borrow one from the pool:

[source,js]
----
Code not translatable
----

Prepared queries can be created:

[source,js]
----
var Tuple = require("vertx-sql-client-js/tuple");
connection.prepare("SELECT * FROM users WHERE first_name LIKE ?", function (ar1, ar1_err) {
  if (ar1_err == null) {
    var pq = ar1;
    pq.execute(Tuple.of("julien"), function (ar2, ar2_err) {
      if (ar2_err == null) {
        // All rows
        var rows = ar2;
      }
    });
  }
});

----

NOTE: prepared query caching depends on the `link:../dataobjects.html#SqlConnectOptions#setCachePreparedStatements[cachePreparedStatements]` and
does not depend on whether you are creating prepared queries or use `link:../../jsdoc/module-vertx-sql-client-js_sql_client-SqlClient.html#preparedQuery[direct prepared queries]`

`link:../../jsdoc/module-vertx-sql-client-js_prepared_query-PreparedQuery.html[PreparedQuery]` can perform efficient batching:

[source,js]
----
var Tuple = require("vertx-sql-client-js/tuple");
connection.prepare("INSERT INTO USERS (id, name) VALUES (?, ?)", function (ar1, ar1_err) {
  if (ar1_err == null) {
    var prepared = ar1;

    // Create a query : bind parameters
    var batch = [];

    // Add commands to the createBatch
    batch.push(Tuple.of("julien", "Julien Viet"));
    batch.push(Tuple.of("emad", "Emad Alblueshi"));

    prepared.batch(batch, function (res, res_err) {
      if (res_err == null) {

        // Process rows
        var rows = res;
      } else {
        console.log("Batch failed " + res_err);
      }
    });
  }
});

----