Search in sources :

Example 56 with AnsiDialect

use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.

the class SelectProjectionTest method projectColumns.

@Test
void projectColumns() {
    Database database = TestDatabase.testDatabase(new AnsiDialect());
    Alias<WidgetRow> w = database.table(WidgetRow.class).as("w");
    database.from(w).select(WidgetRow::name, "n1").comma(WidgetRow::description, "d1").comma(WidgetRow::manufacturerId, "m1").comma("w", WidgetRow::name, "n2").comma("w", WidgetRow::description, "d2").comma("w", WidgetRow::manufacturerId, "m2").comma(w, WidgetRow::name, "n3").comma(w, WidgetRow::description, "d3").comma(w, WidgetRow::manufacturerId, "m3").where(WidgetRow::name).isEqualTo("Bob").list(transaction);
    verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
    assertThat(sql.getValue(), is("select " + "w.NAME as n1, w.DESCRIPTION as d1, w.MANUFACTURER_ID as m1, " + "w.NAME as n2, w.DESCRIPTION as d2, w.MANUFACTURER_ID as m2, " + "w.NAME as n3, w.DESCRIPTION as d3, w.MANUFACTURER_ID as m3 " + "from SIESTA.WIDGET w " + "where w.NAME = ?"));
    assertThat(args.getValue(), arrayWithSize(1));
    assertThat(args.getValue()[0], is("Bob"));
}
Also used : WidgetRow(com.cadenzauk.siesta.model.WidgetRow) AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) TestDatabase(com.cadenzauk.siesta.model.TestDatabase) Test(org.junit.jupiter.api.Test) MockitoTest(com.cadenzauk.core.MockitoTest)

Aggregations

AnsiDialect (com.cadenzauk.siesta.dialect.AnsiDialect)56 TestDatabase.testDatabase (com.cadenzauk.siesta.model.TestDatabase.testDatabase)36 Test (org.junit.jupiter.api.Test)32 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 MethodSource (org.junit.jupiter.params.provider.MethodSource)24 WidgetRow (com.cadenzauk.siesta.model.WidgetRow)23 Database (com.cadenzauk.siesta.Database)16 MockitoTest (com.cadenzauk.core.MockitoTest)14 SalespersonRow (com.cadenzauk.siesta.model.SalespersonRow)10 TestDatabase (com.cadenzauk.siesta.model.TestDatabase)10 ManufacturerRow (com.cadenzauk.siesta.model.ManufacturerRow)8 UncheckedAutoCloseable (com.cadenzauk.core.lang.UncheckedAutoCloseable)5 InWhereExpectingAnd (com.cadenzauk.siesta.grammar.select.InWhereExpectingAnd)4 Scope (com.cadenzauk.siesta.Scope)3 Timestamp (java.sql.Timestamp)3 RandomValues.randomLocalDate (com.cadenzauk.core.RandomValues.randomLocalDate)2 RandomValues.randomLocalDateTime (com.cadenzauk.core.RandomValues.randomLocalDateTime)2 InvalidJoinException (com.cadenzauk.siesta.grammar.InvalidJoinException)2 LocalDate (java.time.LocalDate)2 LocalDateTime (java.time.LocalDateTime)2