mirror of https://github.com/AMT-Cheif/drift.git
Document order-by clauses
This commit is contained in:
parent
e018f6d725
commit
824b5b4438
19
README.md
19
README.md
|
@ -137,6 +137,16 @@ and `isSmallerThan`. You can compose expressions using `and(a, b), or(a, b)` and
|
||||||
#### Limit
|
#### Limit
|
||||||
You can limit the amount of results returned by calling `limit` on queries. The method accepts
|
You can limit the amount of results returned by calling `limit` on queries. The method accepts
|
||||||
the amount of rows to return and an optional offset.
|
the amount of rows to return and an optional offset.
|
||||||
|
#### Ordering
|
||||||
|
You can use the `orderBy` method on the select statement. It expects a list of functions that extract the individual
|
||||||
|
ordering terms from the table.
|
||||||
|
```dart
|
||||||
|
Future<List<TodoEntry>> sortEntriesAlphabetically() {
|
||||||
|
return (select(todos)..orderBy([(t) => OrderingTerm(expression: t.title)])).get();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
You can also reverse the order by setting the `mode` property of the `OrderingTerm` to
|
||||||
|
`OrderingMode.desc`.
|
||||||
### Updates and deletes
|
### Updates and deletes
|
||||||
You can use the generated `row` class to update individual fields of any row:
|
You can use the generated `row` class to update individual fields of any row:
|
||||||
```dart
|
```dart
|
||||||
|
@ -154,7 +164,7 @@ Future feelingLazy() {
|
||||||
return (delete(todos)..limit(10)).go();
|
return (delete(todos)..limit(10)).go();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
__⚠️ Caution:__ If you don't explicitly add a `where` or `limit` clause on updates or deletes,
|
__⚠️ Caution:__ If you don't explicitly add a `where` clause on updates or deletes,
|
||||||
the statement will affect all rows in the table!
|
the statement will affect all rows in the table!
|
||||||
|
|
||||||
### Inserts
|
### Inserts
|
||||||
|
@ -218,17 +228,10 @@ You can also add individual tables or drop them.
|
||||||
- No joins
|
- No joins
|
||||||
- No `group by` or window functions
|
- No `group by` or window functions
|
||||||
- Custom primary key support is very limited
|
- Custom primary key support is very limited
|
||||||
- No `ORDER BY`
|
|
||||||
|
|
||||||
### Planned for the future
|
### Planned for the future
|
||||||
These aren't sorted by priority. If you have more ideas or want some features happening soon,
|
These aren't sorted by priority. If you have more ideas or want some features happening soon,
|
||||||
let us know by creating an issue!
|
let us know by creating an issue!
|
||||||
|
|
||||||
- Refactor comparison API
|
|
||||||
1. Instead of defining them in `IntColumn`, move `isBiggerThan` and `isSmallerThan` into
|
|
||||||
a new class (comparable expression?)
|
|
||||||
2. Support for non-strict comparisons (<=, >=)
|
|
||||||
3. Support `ORDER BY` clauses.
|
|
||||||
- Specify primary keys
|
- Specify primary keys
|
||||||
- Simple `COUNT(*)` operations (group operations will be much more complicated)
|
- Simple `COUNT(*)` operations (group operations will be much more complicated)
|
||||||
- Support default values and expressions
|
- Support default values and expressions
|
||||||
|
|
|
@ -137,6 +137,16 @@ and `isSmallerThan`. You can compose expressions using `and(a, b), or(a, b)` and
|
||||||
#### Limit
|
#### Limit
|
||||||
You can limit the amount of results returned by calling `limit` on queries. The method accepts
|
You can limit the amount of results returned by calling `limit` on queries. The method accepts
|
||||||
the amount of rows to return and an optional offset.
|
the amount of rows to return and an optional offset.
|
||||||
|
#### Ordering
|
||||||
|
You can use the `orderBy` method on the select statement. It expects a list of functions that extract the individual
|
||||||
|
ordering terms from the table.
|
||||||
|
```dart
|
||||||
|
Future<List<TodoEntry>> sortEntriesAlphabetically() {
|
||||||
|
return (select(todos)..orderBy([(t) => OrderingTerm(expression: t.title)])).get();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
You can also reverse the order by setting the `mode` property of the `OrderingTerm` to
|
||||||
|
`OrderingMode.desc`.
|
||||||
### Updates and deletes
|
### Updates and deletes
|
||||||
You can use the generated `row` class to update individual fields of any row:
|
You can use the generated `row` class to update individual fields of any row:
|
||||||
```dart
|
```dart
|
||||||
|
@ -218,17 +228,10 @@ You can also add individual tables or drop them.
|
||||||
- No joins
|
- No joins
|
||||||
- No `group by` or window functions
|
- No `group by` or window functions
|
||||||
- Custom primary key support is very limited
|
- Custom primary key support is very limited
|
||||||
- No `ORDER BY`
|
|
||||||
|
|
||||||
### Planned for the future
|
### Planned for the future
|
||||||
These aren't sorted by priority. If you have more ideas or want some features happening soon,
|
These aren't sorted by priority. If you have more ideas or want some features happening soon,
|
||||||
let us know by creating an issue!
|
let us know by creating an issue!
|
||||||
|
|
||||||
- Refactor comparison API
|
|
||||||
1. Instead of defining them in `IntColumn`, move `isBiggerThan` and `isSmallerThan` into
|
|
||||||
a new class (comparable expression?) ✔️
|
|
||||||
2. Support for non-strict comparisons (<=, >=) ✔️
|
|
||||||
3. Support `ORDER BY` clauses.
|
|
||||||
- Specify primary keys
|
- Specify primary keys
|
||||||
- Simple `COUNT(*)` operations (group operations will be much more complicated)
|
- Simple `COUNT(*)` operations (group operations will be much more complicated)
|
||||||
- Support default values and expressions
|
- Support default values and expressions
|
||||||
|
|
|
@ -62,8 +62,8 @@ class Database extends _$Database {
|
||||||
Stream<List<TodoEntry>> get todosWithoutCategories =>
|
Stream<List<TodoEntry>> get todosWithoutCategories =>
|
||||||
(select(todos)..where((t) => isNull(t.category))).watch();
|
(select(todos)..where((t) => isNull(t.category))).watch();
|
||||||
|
|
||||||
Future test() {
|
Future<List<TodoEntry>> sortEntriesAlphabetically() {
|
||||||
|
return (select(todos)..orderBy([(u) => OrderingTerm(expression: u.title)])).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future addTodoEntry(TodoEntry entry) {
|
Future addTodoEntry(TodoEntry entry) {
|
||||||
|
|
Loading…
Reference in New Issue