Search in sources :

Example 11 with InsertQuery

use of jakarta.nosql.query.InsertQuery in project jnosql-diana by eclipse.

the class InsertQueryProviderTest method shouldReturnParserQuery10.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (name = \"Diana\") 10 second" })
public void shouldReturnParserQuery10(String query) {
    InsertQuery insertQuery = checkInsertFromStart(query);
    checkTTL(insertQuery, Duration.ofSeconds(10L));
}
Also used : InsertQuery(jakarta.nosql.query.InsertQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with InsertQuery

use of jakarta.nosql.query.InsertQuery in project jnosql-diana by eclipse.

the class InsertQueryProviderTest method shouldReturnParserQuery6.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (age = 30, name = \"Artemis\")" })
public void shouldReturnParserQuery6(String query) {
    InsertQuery insertQuery = checkInsertFromStart(query);
    List<Condition> conditions = insertQuery.getConditions();
    assertEquals(2, conditions.size());
    Condition condition = conditions.get(0);
    assertEquals("age", condition.getName());
    assertEquals(Operator.EQUALS, condition.getOperator());
    QueryValue<?> value = condition.getValue();
    assertTrue(value instanceof NumberQueryValue);
    assertEquals(30L, NumberQueryValue.class.cast(value).get());
    condition = conditions.get(1);
    assertEquals("name", condition.getName());
    assertEquals(Operator.EQUALS, condition.getOperator());
    value = condition.getValue();
    assertTrue(value instanceof StringQueryValue);
    assertEquals("Artemis", StringQueryValue.class.cast(value).get());
    assertFalse(insertQuery.getTtl().isPresent());
}
Also used : Condition(jakarta.nosql.query.Condition) NumberQueryValue(jakarta.nosql.query.NumberQueryValue) InsertQuery(jakarta.nosql.query.InsertQuery) StringQueryValue(jakarta.nosql.query.StringQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with InsertQuery

use of jakarta.nosql.query.InsertQuery in project jnosql-diana by eclipse.

the class InsertQueryProviderTest method shouldReturnParserQuery13.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (name = 'Diana') 10 nanosecond" })
public void shouldReturnParserQuery13(String query) {
    InsertQuery insertQuery = checkInsertFromStart(query);
    checkTTL(insertQuery, Duration.ofNanos(10L));
}
Also used : InsertQuery(jakarta.nosql.query.InsertQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with InsertQuery

use of jakarta.nosql.query.InsertQuery in project jnosql-diana by eclipse.

the class InsertQueryParser method query.

Stream<ColumnEntity> query(String query, ColumnFamilyManager manager, ColumnObserverParser observer) {
    InsertQuery insertQuery = insertQueryProvider.apply(query);
    String columnFamily = insertQuery.getEntity();
    Params params = Params.newParams();
    ColumnEntity entity = getEntity(insertQuery, columnFamily, params, observer);
    Optional<Duration> ttl = insertQuery.getTtl();
    if (params.isNotEmpty()) {
        throw new QueryException("To run a query with a parameter use a PrepareStatement instead.");
    }
    if (ttl.isPresent()) {
        return Stream.of(manager.insert(entity, ttl.get()));
    } else {
        return Stream.of(manager.insert(entity));
    }
}
Also used : InsertQuery(jakarta.nosql.query.InsertQuery) QueryException(jakarta.nosql.QueryException) ColumnEntity(jakarta.nosql.column.ColumnEntity) Params(jakarta.nosql.Params) Duration(java.time.Duration)

Example 15 with InsertQuery

use of jakarta.nosql.query.InsertQuery in project jnosql-diana by eclipse.

the class InsertQueryProviderTest method shouldReturnParserQuery8.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (name = \"Diana\") 10 hour" })
public void shouldReturnParserQuery8(String query) {
    InsertQuery insertQuery = checkInsertFromStart(query);
    checkTTL(insertQuery, Duration.ofHours(10L));
}
Also used : InsertQuery(jakarta.nosql.query.InsertQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

InsertQuery (jakarta.nosql.query.InsertQuery)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 ValueSource (org.junit.jupiter.params.provider.ValueSource)16 Condition (jakarta.nosql.query.Condition)7 JsonObject (javax.json.JsonObject)5 Params (jakarta.nosql.Params)4 JSONQueryValue (jakarta.nosql.query.JSONQueryValue)4 Duration (java.time.Duration)4 NumberQueryValue (jakarta.nosql.query.NumberQueryValue)3 QueryException (jakarta.nosql.QueryException)2 ColumnEntity (jakarta.nosql.column.ColumnEntity)2 DocumentEntity (jakarta.nosql.document.DocumentEntity)2 StringQueryValue (jakarta.nosql.query.StringQueryValue)2 Function (jakarta.nosql.query.Function)1 FunctionQueryValue (jakarta.nosql.query.FunctionQueryValue)1 ParamQueryValue (jakarta.nosql.query.ParamQueryValue)1 JsonArray (javax.json.JsonArray)1