Search in sources :

Example 1 with SQLPredicate

use of com.amplifyframework.datastore.storage.sqlite.adapter.SQLPredicate in project amplify-android by aws-amplify.

the class SQLPredicateTest method testContainsForStringField.

/**
 * Test contains in the context of a String field.
 * @throws DataStoreException Not thrown.
 */
@Test
public void testContainsForStringField() throws DataStoreException {
    QueryPredicate predicate = Where.matches(Blog.NAME.contains("something")).getQueryPredicate();
    SQLPredicate sqlPredicate = new SQLPredicate(predicate);
    validateSQLExpressionForContains(sqlPredicate, "name");
}
Also used : SQLPredicate(com.amplifyframework.datastore.storage.sqlite.adapter.SQLPredicate) QueryPredicate(com.amplifyframework.core.model.query.predicate.QueryPredicate) Test(org.junit.Test)

Example 2 with SQLPredicate

use of com.amplifyframework.datastore.storage.sqlite.adapter.SQLPredicate in project amplify-android by aws-amplify.

the class SQLPredicateTest method testNotContainsForStringField.

/**
 * Test notContains in the context of a String field.
 * @throws DataStoreException Not thrown.
 */
@Test
public void testNotContainsForStringField() throws DataStoreException {
    QueryPredicate predicate = Where.matches(Blog.NAME.notContains("something")).getQueryPredicate();
    SQLPredicate sqlPredicate = new SQLPredicate(predicate);
    validateSQLExpressionForNotContains(sqlPredicate, "name");
}
Also used : SQLPredicate(com.amplifyframework.datastore.storage.sqlite.adapter.SQLPredicate) QueryPredicate(com.amplifyframework.core.model.query.predicate.QueryPredicate) Test(org.junit.Test)

Example 3 with SQLPredicate

use of com.amplifyframework.datastore.storage.sqlite.adapter.SQLPredicate in project amplify-android by aws-amplify.

the class SQLPredicateTest method testMatchAllPredicate.

/**
 * Test that MATCH ALL predicate is correctly parsed to an
 * expression that is always true.
 * @throws DataStoreException if parsing fails
 */
@Test
public void testMatchAllPredicate() throws DataStoreException {
    QueryPredicate predicate = QueryPredicates.all();
    SQLPredicate sqlPredicate = new SQLPredicate(predicate);
    assertEquals("1 = 1", sqlPredicate.toString());
    assertTrue(sqlPredicate.getBindings().isEmpty());
}
Also used : SQLPredicate(com.amplifyframework.datastore.storage.sqlite.adapter.SQLPredicate) QueryPredicate(com.amplifyframework.core.model.query.predicate.QueryPredicate) Test(org.junit.Test)

Example 4 with SQLPredicate

use of com.amplifyframework.datastore.storage.sqlite.adapter.SQLPredicate in project amplify-android by aws-amplify.

the class SQLPredicateTest method testNotContainsForStringList.

/**
 * Test notContains in the context of a list.
 * @throws DataStoreException Not thrown.
 */
@Test
public void testNotContainsForStringList() throws DataStoreException {
    QueryPredicateOperation<String> predicate = Blog.TAGS.notContains("something");
    SQLPredicate sqlPredicate = new SQLPredicate(predicate);
    validateSQLExpressionForNotContains(sqlPredicate, "tags");
}
Also used : SQLPredicate(com.amplifyframework.datastore.storage.sqlite.adapter.SQLPredicate) Test(org.junit.Test)

Example 5 with SQLPredicate

use of com.amplifyframework.datastore.storage.sqlite.adapter.SQLPredicate in project amplify-android by aws-amplify.

the class SQLiteCommandFactory method deleteFor.

@NonNull
@Override
public SqlCommand deleteFor(@NonNull ModelSchema modelSchema, @NonNull QueryPredicate predicate) throws DataStoreException {
    final SQLiteTable table = SQLiteTable.fromSchema(modelSchema);
    final SQLPredicate sqlPredicate = new SQLPredicate(predicate);
    final String preparedDeleteStatement = "DELETE FROM" + SqlKeyword.DELIMITER + Wrap.inBackticks(table.getName()) + SqlKeyword.DELIMITER + SqlKeyword.WHERE + SqlKeyword.DELIMITER + sqlPredicate + ";";
    return new SqlCommand(table.getName(), preparedDeleteStatement, // WHERE clause
    sqlPredicate.getBindings());
}
Also used : SQLPredicate(com.amplifyframework.datastore.storage.sqlite.adapter.SQLPredicate) SQLiteTable(com.amplifyframework.datastore.storage.sqlite.adapter.SQLiteTable) NonNull(androidx.annotation.NonNull)

Aggregations

SQLPredicate (com.amplifyframework.datastore.storage.sqlite.adapter.SQLPredicate)12 Test (org.junit.Test)8 QueryPredicate (com.amplifyframework.core.model.query.predicate.QueryPredicate)6 NonNull (androidx.annotation.NonNull)4 SQLiteTable (com.amplifyframework.datastore.storage.sqlite.adapter.SQLiteTable)4 SQLiteColumn (com.amplifyframework.datastore.storage.sqlite.adapter.SQLiteColumn)2 ArrayList (java.util.ArrayList)2 QueryPaginationInput (com.amplifyframework.core.model.query.QueryPaginationInput)1 QuerySortBy (com.amplifyframework.core.model.query.QuerySortBy)1 QueryPredicateOperation (com.amplifyframework.core.model.query.predicate.QueryPredicateOperation)1 HashMap (java.util.HashMap)1 List (java.util.List)1