Search in sources :

Example 11 with WidgetRow

use of com.cadenzauk.siesta.model.WidgetRow in project siesta by cadenzauk.

the class CoalesceFunctionTest method coalesceTest.

@ParameterizedTest
@MethodSource("parametersForCoalesce")
void coalesceTest(String name, Function<Alias<WidgetRow>, CoalesceFunction<String>> f, String expected) {
    Database database = testDatabase(new AnsiDialect());
    Alias<WidgetRow> w = database.table(WidgetRow.class).as("w");
    String sql = database.from(w).select(f.apply(w), "name").where(WidgetRow::manufacturerId).isEqualTo(2L).sql();
    assertThat(sql, is("select " + expected + " as name " + "from SIESTA.WIDGET w " + "where w.MANUFACTURER_ID = ?"));
}
Also used : WidgetRow(com.cadenzauk.siesta.model.WidgetRow) AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Database(com.cadenzauk.siesta.Database) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 12 with WidgetRow

use of com.cadenzauk.siesta.model.WidgetRow in project siesta by cadenzauk.

the class SelectExpressionTest method coalesceFunc.

@Test
void coalesceFunc() {
    Database database = testDatabase(new AnsiDialect());
    Alias<WidgetRow> w = database.table(WidgetRow.class).as("w");
    String sql = database.from(w).select(coalesce(WidgetRow::name).orElse(WidgetRow::description).orElse("Bob"), "name").where(WidgetRow::manufacturerId).isEqualTo(2L).sql();
    assertThat(sql, is("select coalesce(w.NAME, w.DESCRIPTION, ?) as name " + "from SIESTA.WIDGET w " + "where w.MANUFACTURER_ID = ?"));
}
Also used : WidgetRow(com.cadenzauk.siesta.model.WidgetRow) AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Test(org.junit.jupiter.api.Test)

Example 13 with WidgetRow

use of com.cadenzauk.siesta.model.WidgetRow in project siesta by cadenzauk.

the class SelectExpressionTest method substrFunc.

@Test
void substrFunc() {
    Database database = testDatabase(new AnsiDialect());
    Alias<WidgetRow> w = database.table(WidgetRow.class).as("w");
    String sql = database.from(w).select(substr(w.column(WidgetRow::name), 4), "name").where(WidgetRow::manufacturerId).isEqualTo(2L).sql();
    assertThat(sql, is("select substr(w.NAME, ?) as name " + "from SIESTA.WIDGET w " + "where w.MANUFACTURER_ID = ?"));
}
Also used : WidgetRow(com.cadenzauk.siesta.model.WidgetRow) AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Test(org.junit.jupiter.api.Test)

Example 14 with WidgetRow

use of com.cadenzauk.siesta.model.WidgetRow in project siesta by cadenzauk.

the class SelectExpressionTest method isIn.

@Test
void isIn() {
    Database database = testDatabase(new AnsiDialect());
    String sql = database.from(WidgetRow.class).where(WidgetRow::widgetId).isIn(123L, 456L).sql();
    assertThat(sql, is("select WIDGET.WIDGET_ID as WIDGET_WIDGET_ID, " + "WIDGET.NAME as WIDGET_NAME, " + "WIDGET.MANUFACTURER_ID as WIDGET_MANUFACTURER_ID, " + "WIDGET.DESCRIPTION as WIDGET_DESCRIPTION " + "from SIESTA.WIDGET WIDGET " + "where WIDGET.WIDGET_ID in (?, ?)"));
}
Also used : WidgetRow(com.cadenzauk.siesta.model.WidgetRow) AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Test(org.junit.jupiter.api.Test)

Example 15 with WidgetRow

use of com.cadenzauk.siesta.model.WidgetRow in project siesta by cadenzauk.

the class SelectExpressionTest method isLikeEscape.

@Test
void isLikeEscape() {
    Database database = testDatabase(new AnsiDialect());
    String sql = database.from(WidgetRow.class).where(WidgetRow::name).isLike("abc@%%", "@").sql();
    assertThat(sql, is("select WIDGET.WIDGET_ID as WIDGET_WIDGET_ID, " + "WIDGET.NAME as WIDGET_NAME, " + "WIDGET.MANUFACTURER_ID as WIDGET_MANUFACTURER_ID, " + "WIDGET.DESCRIPTION as WIDGET_DESCRIPTION " + "from SIESTA.WIDGET WIDGET " + "where WIDGET.NAME like ? escape '@'"));
}
Also used : WidgetRow(com.cadenzauk.siesta.model.WidgetRow) AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Test(org.junit.jupiter.api.Test)

Aggregations

WidgetRow (com.cadenzauk.siesta.model.WidgetRow)37 Test (org.junit.jupiter.api.Test)32 TestDatabase.testDatabase (com.cadenzauk.siesta.model.TestDatabase.testDatabase)26 AnsiDialect (com.cadenzauk.siesta.dialect.AnsiDialect)23 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 MockitoTest (com.cadenzauk.core.MockitoTest)9 ManufacturerRow (com.cadenzauk.siesta.model.ManufacturerRow)8 TestDatabase (com.cadenzauk.siesta.model.TestDatabase)8 Database (com.cadenzauk.siesta.Database)7 Tuple2 (com.cadenzauk.core.tuple.Tuple2)5 MethodSource (org.junit.jupiter.params.provider.MethodSource)5 Tuple3 (com.cadenzauk.core.tuple.Tuple3)2 TypedExpression.column (com.cadenzauk.siesta.grammar.expression.TypedExpression.column)2 WidgetViewRow (com.cadenzauk.siesta.model.WidgetViewRow)2 Optional (java.util.Optional)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Matchers.is (org.hamcrest.Matchers.is)2 RandomValues (com.cadenzauk.core.RandomValues)1 Tuple5 (com.cadenzauk.core.tuple.Tuple5)1 DatabaseIntegrationTest (com.cadenzauk.siesta.DatabaseIntegrationTest)1