library/src/main/java/ru/noties/storm/DatabaseManager.java
public int count(Class<?> clazz, @Nullable Selection selection) {

        final String tableName = getTableName(clazz);

        final boolean hasSelection = selection != null;

        final Cursor cursor = mDataBase.query(
                tableName,
                new String[] { "count(1)" },
                hasSelection ? selection.getSelection()     : null,
                hasSelection ? selection.getSelectionArgs() : null,
                null,
                null,
                null,
                "1"
        );

        if (cursor == null) {
            return 0;
        }

        final int result;

        if (cursor.moveToFirst()) {
            result = cursor.getInt(0);
        } else {
            result = 0;
        }

        cursor.close();
        return result;
    }
public int count(Class<?> clazz, @Nullable Selection selection) {

        final String tableName = getTableName(clazz);

        final boolean hasSelection = selection != null;

        final Cursor cursor = mDataBase.query(
                tableName,
                new String[] { "count(1)" },
                hasSelection ? selection.getSelection()     : null,
                hasSelection ? selection.getSelectionArgs() : null,
                null,
                null,
                null,
                "1"
        );

        if (cursor == null) {
            return 0;
        }

        final int result;

        if (cursor.moveToFirst()) {
            result = cursor.getInt(0);
        } else {
            result = 0;
        }

        cursor.close();
        return result;
    }
Counts number of rows in specified query. If {@link ru.noties.storm.query.Selection} is null
then counts all rows in Class table.

@param clazz table class
@param selection {@link ru.noties.storm.query.Selection}
@return number of rows from executed query