== 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,ruby]
----
client.query("SELECT * FROM users WHERE id='julien'") { |ar_err,ar|
  if (ar_err == nil)
    result = ar
    puts "Got #{result.size()} rows "
  else
    puts "Failure: #{ar_err.get_message()}"
  end
}

----

You can do the same with prepared queries.

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

[source,ruby]
----
require 'vertx-sql-client/tuple'
client.prepared_query("SELECT * FROM users WHERE id=?", VertxSqlClient::Tuple.of("julien")) { |ar_err,ar|
  if (ar_err == nil)
    rows = ar
    puts "Got #{rows.size()} rows "
  else
    puts "Failure: #{ar_err.get_message()}"
  end
}

----

Query methods provides an asynchronous `link:../../yardoc/VertxSqlClient/RowSet.html[RowSet]` instance that works for _SELECT_ queries

[source,ruby]
----
client.prepared_query("SELECT first_name, last_name FROM users") { |ar_err,ar|
  if (ar_err == nil)
    rows = ar
    rows.each do |row|
      puts "User #{row.get_string(0)} #{row.get_string(1)}"
    end
  else
    puts "Failure: #{ar_err.get_message()}"
  end
}

----

or _UPDATE_/_INSERT_ queries:

[source,ruby]
----
require 'vertx-sql-client/tuple'
client.prepared_query("INSERT INTO users (first_name, last_name) VALUES (?, ?)", VertxSqlClient::Tuple.of("Julien", "Viet")) { |ar_err,ar|
  if (ar_err == nil)
    rows = ar
    puts rows.row_count()
  else
    puts "Failure: #{ar_err.get_message()}"
  end
}

----

The `link:../../yardoc/VertxSqlClient/Row.html[Row]` gives you access to your data by index

[source,ruby]
----
puts "User #{row.get_string(0)} #{row.get_string(1)}"

----

or by name

[source,ruby]
----
puts "User #{row.get_string("first_name")} #{row.get_string("last_name")}"

----

You can access a wide variety of of types

[source,ruby]
----

firstName = row.get_string("first_name")
male = row.get_boolean?("male")
age = row.get_integer("age")

# ...


----

You can execute prepared batch

[source,ruby]
----
# TODO

----

You can cache prepared queries:

[source,ruby]
----
# TODO

----

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

[source,ruby]
----
# TODO

----