Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
g4s8 committed Mar 11, 2017
1 parent 509497c commit 4460cdf
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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")
)
);
}
Expand Down

0 comments on commit 4460cdf

Please sign in to comment.