java.lang.Object
io.github.projectunified.craftdatabase.client.sql.helper.SelectBuilder

public final class SelectBuilder extends Object
A builder for SELECT queries
  • Method Details

    • create

      public static SelectBuilder create(String table)
      Create a new builder
      Parameters:
      table - the table
      Returns:
      the builder
    • distinct

      public SelectBuilder distinct()
      Add the DISTINCT option
      Returns:
      this builder for chaining
    • columns

      public SelectBuilder columns(String... columns)
      Add columns to select, the default is *
      Parameters:
      columns - the columns
      Returns:
      this builder for chaining
    • join

      public SelectBuilder join(String join, Object... values)
      Add a join clause, e.g. join("LEFT JOIN orders o ON o.user_id = u.id")
      Parameters:
      join - the join clause
      values - the values for the placeholders, omitted to provide them later in a batch
      Returns:
      this builder for chaining
    • where

      public SelectBuilder where(String condition, Object... values)
      Add a condition, joined to the previous ones with AND
      Parameters:
      condition - the condition, the ? placeholders must match the values
      values - the values for the placeholders, omitted to provide them later in a batch
      Returns:
      this builder for chaining
    • groupBy

      public SelectBuilder groupBy(String... columns)
      Add columns to group by
      Parameters:
      columns - the columns
      Returns:
      this builder for chaining
    • having

      public SelectBuilder having(String condition, Object... values)
      Add a condition to the HAVING clause, joined to the previous ones with AND
      Parameters:
      condition - the condition, the ? placeholders must match the values
      values - the values for the placeholders, omitted to provide them later in a batch
      Returns:
      this builder for chaining
    • orderBy

      public SelectBuilder orderBy(String... orderBy)
      Add an order by expression, e.g. "id DESC"
      Parameters:
      orderBy - the order by expression
      Returns:
      this builder for chaining
    • limit

      public SelectBuilder limit(int limit)
      Set the maximum number of rows
      Parameters:
      limit - the limit
      Returns:
      this builder for chaining
    • build

      public Query build()
      Build the query
      Returns:
      the query