== Running queries

When you don't need a transaction or run single queries, you can run queries directly on the pool; the pool
will use one of its connection to run the query and return the result to you.

Here is how to run simple queries:

[source,js]
----
client.query("SELECT * FROM users WHERE id='julien'", function (ar, ar_err) {
  if (ar_err == null) {
    var result = ar;
    console.log("Got " + result.size() + " rows ");
  } else {
    console.log("Failure: " + ar_err.getMessage());
  }
});

----

You can do the same with prepared queries.

The SQL string can refer to parameters by position, using `$1`, `$2`, etc…​

[source,js]
----
var Tuple = require("vertx-sql-client-js/tuple");
client.preparedQuery("SELECT * FROM users WHERE id=?", Tuple.of("julien"), function (ar, ar_err) {
  if (ar_err == null) {
    var rows = ar;
    console.log("Got " + rows.size() + " rows ");
  } else {
    console.log("Failure: " + ar_err.getMessage());
  }
});

----

Query methods provides an asynchronous `link:../../jsdoc/module-vertx-sql-client-js_row_set-RowSet.html[RowSet]` instance that works for _SELECT_ queries

[source,js]
----
client.preparedQuery("SELECT first_name, last_name FROM users", function (ar, ar_err) {
  if (ar_err == null) {
    var rows = ar;
    Array.prototype.forEach.call(rows, function(row) {
      console.log("User " + row.getString(0) + " " + row.getString(1));
    });
  } else {
    console.log("Failure: " + ar_err.getMessage());
  }
});

----

or _UPDATE_/_INSERT_ queries:

[source,js]
----
var Tuple = require("vertx-sql-client-js/tuple");
client.preparedQuery("INSERT INTO users (first_name, last_name) VALUES (?, ?)", Tuple.of("Julien", "Viet"), function (ar, ar_err) {
  if (ar_err == null) {
    var rows = ar;
    console.log(rows.rowCount());
  } else {
    console.log("Failure: " + ar_err.getMessage());
  }
});

----

The `link:../../jsdoc/module-vertx-sql-client-js_row-Row.html[Row]` gives you access to your data by index

[source,js]
----
console.log("User " + row.getString(0) + " " + row.getString(1));

----

or by name

[source,js]
----
console.log("User " + row.getString("first_name") + " " + row.getString("last_name"));

----

You can access a wide variety of of types

[source,js]
----

var firstName = row.getString("first_name");
var male = row.getBoolean("male");
var age = row.getInteger("age");

// ...


----

You can execute prepared batch

[source,js]
----
// TODO

----

You can cache prepared queries:

[source,js]
----
// TODO

----

You can fetch generated keys with a 'RETURNING' clause in your query:

[source,js]
----
// TODO

----