public function calculation($type, $query, array $options = []) {
		$query->calculate($type);

		switch ($type) {
			case 'count':
				if (strpos($fields = $this->fields($query->fields(), $query), ',') !== false) {
					$fields = "*";
				}
				$query->fields("COUNT({$fields}) as count", true);
				$query->map([$query->alias() => ['count']]);

				$result = $this->read($query, $options)->data();

				if (!$result || !isset($result[0]['count'])) {
					return null;
				}
				return (integer) $result[0]['count'];
		}
	}