The Database
class first lets you establish a connection
to a JDBC driver. It then provides support to create and drop tables,
and create various kinds of statements. It also manages statement
caches, so each unique statement need only be prepared once. A typical
usage is shown in the introductions:
db.select(People.columns).from(People) + "WHERE " + People.name + " <> " + param run { query -> ... }The call to
db.select(...)
yields an instance of
SelectQuery.Builder
. This object has a
From(Table)
method that returns the same builder.
The builder also defines the +
operator for appropriate
types, allowing a full statement to be build up. Finally, the
infix run
operator is applied to the builder.
The run
operator takes a lambda that accepts a
SelectQuery
. See the
statements description for what happens next.
The other statement types work similarly. There are some differences, though.
For example, an INSERT
statement never has a WHERE
clause, or other functionality that would require it to accept text or
parameters.
Update
is a little special, in that each column sent to the
Builder will result in a value that needs to be provided
in the
next step;
for the other statement types, it is only
Parameter
objects that generate a need to supply a value.