getSingle method

  1. @override
Future<T> getSingle()

Executes this statement, like Selectable.get, but only returns one value. the query returns no or too many rows, the returned future will complete with an error.

Be aware that this operation won't put a limit clause on this statement, if that's needed you would have to do use SimpleSelectStatement.limit:

Future<TodoEntry> loadMostImportant() {
  return (select(todos)
   ..orderBy([(t) =>
      OrderingTerm(expression: t.priority, mode: OrderingMode.desc)])

You should only use this method if you know the query won't have more than one row, for instance because you used limit(1) or you know the where clause will only allow one row.

See also: Selectable.getSingleOrNull, which returns null instead of throwing if the query completes with no rows.


Future<T> getSingle() async {
  return (await get()).single;