function count($filter = NULL, $ttl = 0)
{
$sql = 'SELECT COUNT(*) AS ' . $this->db->quotekey('rows') . ' FROM ' . $this->table;
$args = [];
if ($filter) {
if (is_array($filter)) {
$args = isset($filter[1]) && is_array($filter[1]) ? $filter[1] : array_slice($filter, 1, NULL, TRUE);
$args = is_array($args) ? $args : [1 => $args];
list($filter) = $filter;
}
$sql .= ' WHERE ' . $filter;
}
$result = $this->db->exec($sql, $args, $ttl);
return $result[0]['rows'];
}