diff --git a/README.md b/README.md index 8bbf191..50f0fb9 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,47 @@ QueryLite is a fluent query API for android sqlite database. -**Query** - fluent sqlite query that supports `where`, `orderBy` and `limit` yet. (`distinct`, `having` and `groupBy` will be supported later). +## Classes + +### Table, TableSqlite and Table.Wrap +`Table` represents a database table. `Table` used by `Select.from(table)` to create new `Query`. `TableSqlite` - sqlite table (takes android `SQLiteDatabase` as argument), +`Table.Wrap` - default `Table` decorator. `TableSqlite` can be wrapped with `Table.Wrap`: +```java +public final class CarTable extends Table.Wrap { + + /** + * Table name. + */ + private static final String NAME = "cars"; + + public CarTable(final SQLiteDatabase database) { + super( + new TableSqlite( + CarTable.NAME, + database + ) + ); + } +} +``` + +### Select +`Select` shoud specify columns to select from `Table`, `Select.from` can be wrapped with `Query.Wrap` decorator: +```java +public final class CarEngineQuery extends Query.Wrap { + + public CarEngineQuery(final SQLiteDatabase database) { + super( + new Select("engine") + .from(new CarTable(database)) + ); + } +} +``` + +### Query and Query.Wrap +`Query` - fluent sqlite query that supports `where`, `orderBy` and `limit` yet. (`distinct`, `having` and `groupBy` will be supported later). + `where` - produces [sqlite WHERE clause](https://www.sqlite.org/lang_select.html#whereclause). > If a WHERE clause is specified, the WHERE expression is evaluated for each row in the input data as a boolean expression. Only rows for which the WHERE clause expression evaluates to true are included from the dataset before continuing. Rows are excluded from the result if the WHERE clause evaluates to either false or NULL. @@ -41,16 +81,18 @@ query .where("id = ? AND name = ?", 42, "David") ``` + ### CursorQuery It's a decorator for android [Cursor](https://developer.android.com/reference/android/database/Cursor.html), that take `Query` as argument: ```java import android.database.CursorWrapper; -public final class ItemsByName extends CursorWrapper { - public ItemsByName(final Query query) { +public final class OrderedCarEnginesCursor extends CursorWrapper { + public OrderedCarEnginesCursor(final SQLiteDatabase database) { super( new CursorQuery( - query.orderBy("name") + new CarEngineQuery(database) + .orderBy("engine") ) ); }