count method
Count records in a table.
Implementation
Future<int> count({
required String table,
String? text,
List<double>? vector,
dynamic where, // String or Map<String, dynamic>
List<String>? namespace,
}) async {
// If 'where' is a Map, convert it to an AND-joined string.
String? whereClause;
if (where is Map<String, dynamic>) {
final parts = <String>[];
where.forEach((key, value) {
parts.add("$key = ${_escapeValue(value)}");
});
whereClause = parts.join(" AND ");
} else if (where is String) {
whereClause = where;
}
final payload = <String, dynamic>{"table": table, "where": whereClause, "text": text};
if (vector != null) {
payload["vector"] = vector;
}
payload["namespace"] = namespace;
final response = (await room.sendRequest("database.count", payload) as JsonResponse);
// If your sendRequest returns a structure like { "json": { "results": [...] } }
// Then parse it accordingly:
return (response.json["count"] as num).toInt();
}