Package com.gengoai.sql
Class SQL
- java.lang.Object
-
- com.gengoai.sql.SQL
-
public final class SQL extends Object
DSL for using Mango SQL
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SQL.F
Set of commonly used SQL functionsstatic class
SQL.TableDef
-
Field Summary
Fields Modifier and Type Field Description static SQLElement
ALL
SQLElement representing "*" for selecting ALLstatic SQLElement
INDEXED_ARGUMENT
SQLElement representing "?" of use with PreparedStatements
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static SQLOperable
and(@NonNull SQLElement... elements)
Combines one or more SQLElements via anAND
static SQLOperable
C(@NonNull Table table, String column)
static SQLOperable
C(String column)
AnSQLOperable
defining a column name.static SQLOperable
C(String table, String column)
AnSQLOperable
defining a fully qualified column name.static Column
column(String name, String type)
Static method for constructing a new Column given its name and type.static boolean
columnNamesEqual(String c1, String c2)
static SQLOperable
exists(@NonNull QueryStatement query)
Creates an "exists" cause checking for the existence of a record in a sub query.static SQLOperable
group(@NonNull SQLElement... elements)
Groups one or more expressions by placing them in parenthesisstatic SQLOperable
L(@NonNull String value)
AnSQLOperable
defining a literal expression, which will automatically be placed in single quotes.static SQLOperable
N(@NonNull Number value)
Generates anSQLOperable
for a numeric valuestatic SQLElement
namedArgument(@NonNull SQLElement name)
Named argument sql element.static SQLOperable
namedArgument(@NonNull String name)
Generates a named argument for use withNamedPreparedStatement
static SQLElement
nullValue()
Generates a null valuestatic SQLOperable
or(@NonNull SQLElement... elements)
Combines one or more SQLElements via anOR
static QueryStatement
query(String statement)
Free form SQL query statementstatic SQLElement
sql(@NonNull String... components)
Free form SQL from one or more sql statementsstatic Table
table(String name, @NonNull Consumer<SQL.TableDef> definition)
static Table
table(String name, SQLElement type, @NonNull Consumer<SQL.TableDef> definition)
static UpdateStatement
update(String statement)
Free form SQL update statement
-
-
-
Field Detail
-
ALL
public static final SQLElement ALL
SQLElement representing "*" for selecting ALL
-
INDEXED_ARGUMENT
public static final SQLElement INDEXED_ARGUMENT
SQLElement representing "?" of use with PreparedStatements
-
-
Method Detail
-
C
public static SQLOperable C(String column)
AnSQLOperable
defining a column name.- Parameters:
column
- the column name- Returns:
- the SQLOperable
-
column
public static Column column(String name, String type)
Static method for constructing a new Column given its name and type.- Parameters:
name
- the name of the columntype
- the data type of the column- Returns:
- the column
-
table
public static Table table(String name, @NonNull @NonNull Consumer<SQL.TableDef> definition)
-
table
public static Table table(String name, SQLElement type, @NonNull @NonNull Consumer<SQL.TableDef> definition)
-
C
public static SQLOperable C(String table, String column)
AnSQLOperable
defining a fully qualified column name.- Parameters:
table
- the table namecolumn
- the column name- Returns:
- the SQLOperable
-
C
public static SQLOperable C(@NonNull @NonNull Table table, String column)
-
L
public static SQLOperable L(@NonNull @NonNull String value)
AnSQLOperable
defining a literal expression, which will automatically be placed in single quotes.- Parameters:
value
- the literal value- Returns:
- the SQLOperable
-
N
public static SQLOperable N(@NonNull @NonNull Number value)
Generates anSQLOperable
for a numeric value- Parameters:
value
- the numeric value- Returns:
- the SQLOperable
-
and
public static SQLOperable and(@NonNull @NonNull SQLElement... elements)
Combines one or more SQLElements via anAND
- Parameters:
elements
- the elements to AND- Returns:
- the SQLOperable
-
exists
public static SQLOperable exists(@NonNull @NonNull QueryStatement query)
Creates an "exists" cause checking for the existence of a record in a sub query.- Parameters:
query
- the sub query- Returns:
- the SQLOperable
-
group
public static SQLOperable group(@NonNull @NonNull SQLElement... elements)
Groups one or more expressions by placing them in parenthesis- Parameters:
elements
- the elements to group- Returns:
- the SQLOperable
-
namedArgument
public static SQLOperable namedArgument(@NonNull @NonNull String name)
Generates a named argument for use withNamedPreparedStatement
- Parameters:
name
- the name of the argument- Returns:
- the SQLOperable
-
namedArgument
public static SQLElement namedArgument(@NonNull @NonNull SQLElement name)
Named argument sql element.- Parameters:
name
- the name- Returns:
- the sql element
-
nullValue
public static SQLElement nullValue()
Generates a null value- Returns:
- the SQLElement
-
or
public static SQLOperable or(@NonNull @NonNull SQLElement... elements)
Combines one or more SQLElements via anOR
- Parameters:
elements
- the elements to OR- Returns:
- the SQLOperable
-
query
public static QueryStatement query(String statement)
Free form SQL query statement- Parameters:
statement
- the statement- Returns:
- the SQLQueryStatement
-
sql
public static SQLElement sql(@NonNull @NonNull String... components)
Free form SQL from one or more sql statements- Parameters:
components
- the components- Returns:
- the sql element
-
update
public static UpdateStatement update(String statement)
Free form SQL update statement- Parameters:
statement
- the statement- Returns:
- the SQLUpdateStatement
-
-