Improve documentation for updated features in 1.3

This commit is contained in:
Simon Binder 2019-04-19 17:32:21 +02:00
parent 165693d635
commit 83f8fdd105
No known key found for this signature in database
GPG Key ID: B807FDF954BA00CF
2 changed files with 30 additions and 5 deletions

View File

@ -2,13 +2,20 @@ import 'package:moor/moor.dart';
import 'package:moor/src/runtime/components/component.dart'; import 'package:moor/src/runtime/components/component.dart';
import 'package:moor/src/runtime/expressions/expression.dart'; import 'package:moor/src/runtime/expressions/expression.dart';
/// A custom expression that can appear in a sql statement.
/// The [CustomExpression.content] will be written into the query without any
/// modification.
///
/// When this statement appears in a query
///
/// See also:
/// - [currentDate] and [currentDateAndTime], which use a [CustomExpression]
/// internally.
class CustomExpression<D, S extends SqlType<D>> extends Expression<D, S> { class CustomExpression<D, S extends SqlType<D>> extends Expression<D, S> {
final String content; final String content;
const CustomExpression(this.content); const CustomExpression(this.content);
@override @override
void writeInto(GenerationContext context) { void writeInto(GenerationContext context) => context.buffer.write(content);
context.buffer.write(content);
}
} }

View File

@ -69,6 +69,21 @@ class JoinedSelectStatement<FirstT, FirstD> extends Query<FirstT, FirstD>
} }
} }
/// Applies the [predicate] as the where clause, which will be used to filter
/// results.
///
/// The clause should only refer to columns defined in one of the tables
/// specified during [SimpleSelectStatement.join].
///
/// With the example of a todos table which refers to categories, we can write
/// something like
/// ```dart
/// final query = select(todos)
/// .join([
/// leftOuterJoin(categories, categories.id.equalsExp(todos.category)),
/// ])
/// ..where(and(todos.name.like("%Important"), categories.name.equals("Work")));
/// ```
void where(Expression<bool, BoolType> predicate) { void where(Expression<bool, BoolType> predicate) {
if (whereExpr == null) { if (whereExpr == null) {
whereExpr = Where(predicate); whereExpr = Where(predicate);
@ -77,10 +92,13 @@ class JoinedSelectStatement<FirstT, FirstD> extends Query<FirstT, FirstD>
} }
} }
/// Orders the results of this staemen
void orderBy(List<OrderingTerm> terms) { void orderBy(List<OrderingTerm> terms) {
orderByExpr = OrderBy(terms); orderByExpr = OrderBy(terms);
} }
/// Creates an auto-updating stream of the result that emits new items
/// whenever any table of this statement changes.
Stream<List<TypedResult>> watch() { Stream<List<TypedResult>> watch() {
final ctx = constructQuery(); final ctx = constructQuery();
final fetcher = QueryStreamFetcher<List<TypedResult>>( final fetcher = QueryStreamFetcher<List<TypedResult>>(
@ -258,8 +276,8 @@ class CustomSelectStatement {
} }
} }
/// A result row in a [JoinedSelectStatement] that can consist of multiple /// A result row in a [JoinedSelectStatement] that can parse the result of
/// entities. /// multiple entities.
class TypedResult { class TypedResult {
/// Creates the result from the parsed table data. /// Creates the result from the parsed table data.
TypedResult(this._parsedData, this.rawData); TypedResult(this._parsedData, this.rawData);