DataBridge Documentation 2.0.17
A Java library for managing database connections and transactions
Loading...
Searching...
No Matches
io.github.kdesp73.databridge.helpers.QueryBuilder Class Reference

Public Member Functions

String build ()
 
QueryBuilder columns (String... columns)
 
QueryBuilder deleteFrom (String table)
 
QueryBuilder from (String table)
 
QueryBuilder insertInto (String table)
 
 QueryBuilder ()
 
void reset ()
 
QueryBuilder select (String... columns)
 
QueryBuilder set (String column, Object value)
 
QueryBuilder update (String table)
 
QueryBuilder values (Object... values)
 
QueryBuilder where (String condition)
 

Detailed Description

A helper class to build SQL queries in a fluent interface style. Provides methods for constructing SQL SELECT, INSERT, UPDATE, and DELETE queries. The builder allows appending different parts of the query step-by-step.

Example usage:

QueryBuilder queryBuilder = new QueryBuilder();
String query = queryBuilder.select("id", "name")
                           .from("users")
                           .where("id = 1")
                           .build();
Author
KDesp73

Constructor & Destructor Documentation

◆ QueryBuilder()

io.github.kdesp73.databridge.helpers.QueryBuilder.QueryBuilder ( )

Initializes a new empty query builder.

Member Function Documentation

◆ select()

QueryBuilder io.github.kdesp73.databridge.helpers.QueryBuilder.select ( String... columns)

Appends the SELECT operator to the query.

Parameters
columnsColumns to select.
Returns
QueryBuilder instance with the updated query.

◆ from()

QueryBuilder io.github.kdesp73.databridge.helpers.QueryBuilder.from ( String table)

Appends the FROM operator to the query.

Parameters
tableTable to select from.
Returns
QueryBuilder instance with the updated query.

◆ where()

QueryBuilder io.github.kdesp73.databridge.helpers.QueryBuilder.where ( String condition)

Appends the WHERE operator to the query.

Parameters
conditionSQL condition.
Returns
QueryBuilder instance with the updated query.

◆ insertInto()

QueryBuilder io.github.kdesp73.databridge.helpers.QueryBuilder.insertInto ( String table)

Appends the INSERT INTO operator to the query.

Parameters
tableTable to insert data into.
Returns
QueryBuilder instance with the updated query.

◆ columns()

QueryBuilder io.github.kdesp73.databridge.helpers.QueryBuilder.columns ( String... columns)

Appends multiple columns inside parentheses for an INSERT query.

Parameters
columnsColumns to add.
Returns
QueryBuilder instance with the updated query.

◆ values()

QueryBuilder io.github.kdesp73.databridge.helpers.QueryBuilder.values ( Object... values)

Appends multiple values inside parentheses for an INSERT query.

Parameters
valuesValues to add.
Returns
QueryBuilder instance with the updated query.

◆ update()

QueryBuilder io.github.kdesp73.databridge.helpers.QueryBuilder.update ( String table)

Appends the UPDATE operator to the query.

Parameters
tableTable to perform the update on.
Returns
QueryBuilder instance with the updated query.

◆ set()

QueryBuilder io.github.kdesp73.databridge.helpers.QueryBuilder.set ( String column,
Object value )

Appends the SET operator along with a column and a value for an UPDATE query.

Parameters
columnColumn name.
valueValue for the column.
Returns
QueryBuilder instance with the updated query.

◆ deleteFrom()

QueryBuilder io.github.kdesp73.databridge.helpers.QueryBuilder.deleteFrom ( String table)

Appends the DELETE FROM operator to the query.

Parameters
tableTable to delete from.
Returns
QueryBuilder instance with the updated query.

◆ reset()

void io.github.kdesp73.databridge.helpers.QueryBuilder.reset ( )

Resets the query builder for a new query. Clears the query and any stored columns or values.

◆ build()

String io.github.kdesp73.databridge.helpers.QueryBuilder.build ( )

Builds and returns the final SQL query.

Returns
The SQL query string.
Exceptions
IllegalStateExceptionIf the query has not been fully constructed.

The documentation for this class was generated from the following file: