Package com.ptsmods.mysqlw.query.builder
Class SelectBuilder
java.lang.Object
com.ptsmods.mysqlw.query.builder.SelectBuilder
-
Method Summary
Modifier and TypeMethodDescriptionSets the alias of the table to select from used when selecting.
Mostly only useful in combination withjoin(Join)
Builds aSELECT
query from this builder.clone()
static SelectBuilder
create
(Database db, SelectBuilder select) Create a new SelectBuilder selecting data from another select query on the givenDatabase
.static SelectBuilder
Create a new SelectBuilder selecting data from the given table on the givenDatabase
.static SelectBuilder
create
(SelectBuilder select) Create a new SelectBuilder for use inBlockBuilder
s.static SelectBuilder
Create a new SelectBuilder for use inBlockBuilder
s.execute()
Executes the built query and parses it into an instance ofSelectResults
.Asynchronously executes the built query and parses it into an instance ofSelectResults
.long
Counts the rows this select builder will select.Counts the rows this select builder will select asynchronously.executeCountMultiple
(Class<T> type) Counts the rows this select builder will select.<T> CompletableFuture<Map<T,
Long>> executeCountMultipleAsync
(Class<T> type) Counts the rows this select builder will select asynchronously.Executes the built query and returns the rawResultSet
.executeRaw()
but asynchronous.getAlias()
getDb()
getJoins()
getLimit()
getOrder()
getTable()
Deprecated.Has been renamed to account for different usages.Groups this query by the given group by.groupBy
(GroupBy.Builder groupBy) Groups this query by the given group by.Groups this query by the specified columns, especially useful in combination with aggregate functions.Sets the table or variable to store the selected data into.Add a new prebuilt join.join
(Join.Builder join) Add a new join formed with a builder.join
(JoinType type, String table, QueryCondition condition) Add a new join.join
(String table, QueryCondition condition) Add a newINNER
join.limit
(int limit) Set the maximum amount of rows that should be returned.
Convenience method forlimit(QueryLimit)
andQueryLimit.limit(int)
.limit
(int limit, int offset) Set the maximum amount of rows that should be returned.
Convenience method forlimit(QueryLimit)
andQueryLimit.limit(int, int)
.limit
(QueryLimit limit) Set the maximum amount of rows that should be returned.order
(QueryOrder order) Sets the order in which the data should be returned.Sets the order in which the data should be returned.
Convenient shorthand fororder(QueryOrder)
andQueryOrder.by(String)
.order
(String column, QueryOrder.OrderDirection direction) Sets the order in which the data should be returned.
Convenient shorthand fororder(QueryOrder)
andQueryOrder.by(String, QueryOrder.OrderDirection)
.removeJoin
(Join join) select
(CharSequence column) Select a column orQueryFunction
.select
(CharSequence... columns) Select columns orQueryFunction
s or any combination.select
(CharSequence column, String name) Select a column orQueryFunction
with a specific name.select
(Iterable<? extends CharSequence> columns) Select columns orQueryFunction
s or any combination.where
(QueryCondition condition) Sets the condition that rows must comply with to be selected.
-
Method Details
-
create
Create a new SelectBuilder selecting data from the given table on the givenDatabase
.- Parameters:
db
- The database to select fromtable
- The table to select from- Returns:
- A new SelectBuilder
-
create
Create a new SelectBuilder selecting data from another select query on the givenDatabase
.- Parameters:
db
- The database to select fromselect
- The query to select from- Returns:
- A new SelectBuilder
-
create
Create a new SelectBuilder for use inBlockBuilder
s.- Parameters:
table
- The table to select from- Returns:
- A new SelectBuilder
-
create
Create a new SelectBuilder for use inBlockBuilder
s.- Parameters:
select
- The query to select from- Returns:
- A new SelectBuilder
-
select
Select a column orQueryFunction
.- Parameters:
column
- The column orQueryFunction
to select- Returns:
- This SelectBuilder
-
select
Select a column orQueryFunction
with a specific name.- Parameters:
column
- The column orQueryFunction
to selectname
- The name to select the column as- Returns:
- This SelectBuilder
-
select
Select columns orQueryFunction
s or any combination.- Parameters:
columns
- The columns orQueryFunction
s or any combination to select- Returns:
- This SelectBuilder
-
select
Select columns orQueryFunction
s or any combination.- Parameters:
columns
- The columns orQueryFunction
s or any combination to select- Returns:
- This SelectBuilder
-
alias
Sets the alias of the table to select from used when selecting.
Mostly only useful in combination withjoin(Join)
- Parameters:
alias
- The alias to use- Returns:
- This SelectBuilder
-
join
Add a newINNER
join.- Parameters:
table
- The table to join withcondition
- The condition to join on, required unless chaining multiple joins on MySQL.- Returns:
- This select builder
-
join
Add a new join.- Parameters:
type
- The type of the new jointable
- The table to join withcondition
- The condition to join on, required unless chaining multiple joins on MySQL.- Returns:
- This SelectBuilder
-
join
Add a new join formed with a builder.- Parameters:
join
- The join to add- Returns:
- This SelectBuilder
-
join
Add a new prebuilt join.- Parameters:
join
- The join to add- Returns:
- This SelectBuilder
-
removeJoin
-
into
Sets the table or variable to store the selected data into.- Parameters:
target
- The target to select into- Returns:
- This SelectBuilder
-
where
Sets the condition that rows must comply with to be selected.- Parameters:
condition
- The condition that rows must comply with- Returns:
- This SelectBuilder
-
groupBy
Groups this query by the specified columns, especially useful in combination with aggregate functions.- Parameters:
columns
- The columns to group by- Returns:
- This SelectBuilder
-
groupBy
Groups this query by the given group by.- Parameters:
groupBy
- The group by to group by- Returns:
- This Select Builder
-
groupBy
Groups this query by the given group by.- Parameters:
groupBy
- The group by to group by- Returns:
- This Select Builder
-
order
Sets the order in which the data should be returned.- Parameters:
order
- The order in which the data should be returned- Returns:
- This SelectBuilder
-
order
Sets the order in which the data should be returned.
Convenient shorthand fororder(QueryOrder)
andQueryOrder.by(String)
.- Parameters:
column
- The order in which the data should be returned- Returns:
- This SelectBuilder
-
order
Sets the order in which the data should be returned.
Convenient shorthand fororder(QueryOrder)
andQueryOrder.by(String, QueryOrder.OrderDirection)
.- Parameters:
column
- The order in which the data should be returneddirection
- The direction to order in- Returns:
- This SelectBuilder
-
limit
Set the maximum amount of rows that should be returned.- Parameters:
limit
- The maximum amount of rows to return- Returns:
- This SelectBuilder
-
limit
Set the maximum amount of rows that should be returned.
Convenience method forlimit(QueryLimit)
andQueryLimit.limit(int)
.- Parameters:
limit
- The maximum amount of rows to return- Returns:
- This SelectBuilder
-
limit
Set the maximum amount of rows that should be returned.
Convenience method forlimit(QueryLimit)
andQueryLimit.limit(int, int)
.- Parameters:
limit
- The maximum amount of rows to returnoffset
- The offset at which to start- Returns:
- This SelectBuilder
-
buildQuery
Builds aSELECT
query from this builder.- Returns:
- The built query
-
executeRaw
Executes the built query and returns the rawResultSet
.- Returns:
- The raw
ResultSet
-
executeRawAsync
executeRaw()
but asynchronous.- Returns:
- A
CompletableFuture
containing the rawResultSet
-
execute
Executes the built query and parses it into an instance ofSelectResults
.- Returns:
- The parsed results
-
executeAsync
Asynchronously executes the built query and parses it into an instance ofSelectResults
.- Returns:
- A
CompletableFuture
contain the parsed results
-
executeCount
public long executeCount()Counts the rows this select builder will select.- Returns:
- The amount of rows counted
-
executeCountAsync
Counts the rows this select builder will select asynchronously.- Returns:
- A
CompletableFuture
containing the counted rows
-
executeCountMultiple
Counts the rows this select builder will select.- Parameters:
type
- The type of the column this query will be grouped by.- Returns:
- The amount of rows counted
-
executeCountMultipleAsync
Counts the rows this select builder will select asynchronously.- Parameters:
type
- The type of the column this query will be grouped by.- Returns:
- A
CompletableFuture
containing the counted rows
-
executeCountRaw
-
executeCountRawAsync
-
getDb
- Returns:
- The database this builder will select from
-
getTable
Deprecated.Has been renamed to account for different usages. UsegetSelectionTarget()
instead.- Returns:
- The table this builder will select from
-
getSelectionTarget
- Returns:
- The table or query this builder will select from
-
getColumns
- Returns:
- The columns this builder will select, mainly for internal purposes.
-
getAlias
- Returns:
- The alias of this table used when selecting
-
getTarget
- Returns:
- The target this builder will select into
-
getCondition
- Returns:
- The condition rows will have to comply with to be selected
-
getLimit
- Returns:
- The maximum amount of rows this builder will return upon selecting
-
getOrder
- Returns:
- The order in which the rows will be sorted upon selecting
-
getJoins
- Returns:
- The joins added to this builder
-
getGroupBy
- Returns:
- The group by statement of this builder
-
clone
-