From 2e2d1b4e6df8bc706ca3441f48456f986ca895f3 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Wed, 20 Jan 2021 21:51:48 +0100 Subject: [PATCH] Document custom sql statements with variables --- docs/content/en/docs/Using SQL/custom_queries.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/content/en/docs/Using SQL/custom_queries.md b/docs/content/en/docs/Using SQL/custom_queries.md index ad938e8b..a5bf8319 100644 --- a/docs/content/en/docs/Using SQL/custom_queries.md +++ b/docs/content/en/docs/Using SQL/custom_queries.md @@ -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 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