Document custom sql statements with variables

This commit is contained in:
Simon Binder 2021-01-20 21:51:48 +01:00
parent 6c1650151e
commit 2e2d1b4e6d
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
1 changed files with 12 additions and 0 deletions

View File

@ -96,6 +96,18 @@ For custom selects, you should use the `readsFrom` parameter to specify from whi
reading. When using a `Stream`, moor will be able to know after which updates the stream should emit
items.
You can also bind SQL variables by using question-mark placeholders and the `variables` parameter:
```dart
Stream<int> amountOfTodosInCategory(int id) {
return customSelect(
'SELECT COUNT(*) AS c FROM todos WHERE category = ?',
variables: [Variable.withInt(id)],
readsFrom: {todos},
).map((row) => row.readInt('c')).watch();
}
```
## Custom update statements
For update and delete statements, you can use `customUpdate`. Just like `customSelect`, that method
also takes a sql statement and optional variables. You can also tell moor which tables will be