Skip to content
This repository was archived by the owner on Sep 26, 2019. It is now read-only.

Query builders

Maarten Zuidhoorn edited this page Nov 5, 2016 · 3 revisions

To make writing queries easier, you can use query builders, for some common tasks.

The following query builders are available:

SELECT query

For the SELECT query, begin by creating a SelectQuery object:

SelectQuery selectQuery = new SelectQuery(String table);

Specify a column

selectQuery.column(String column);

To select multiple columns, just use the method multiple times, or to select all columns you can simply use "*".

Where

selectQuery.where(String expression);
selectQuery.and(String expression); //Alias for .where()

Order by

selectQuery.orderBy(String column, boolean ascending);

Limit

selectQuery.limit(int offset, int rowCount);
selectQuery.limit(int rowCount);

If you don't set the offset, it will be set to 0, which is the default.

Build it

To create a String to use in a Query, call the build() method.

You can use the query builders in a builder-like way as well, like this:

String sql = new SelectQuery("table").column("myColumn").where("id = ?").build();

CREATE TABLE query

Begin by making a CreateTableQuery object, like this:

CreateTableQuery createTableQuery = new CreateTableQuery();

If not exists

createTableQuery.ifNotExists();

Add a column

createTableQuery.column(String column, String settings);

Primary key

createTableQuery.primaryKey(String column);

INSERT query

UPDATE query

DELETE query

Clone this wiki locally