tabularDataByMql method

Future<List<Map<String, dynamic>>> tabularDataByMql(
  1. String organizationId,
  2. dynamic query, {
  3. bool useRecentData = false,
})

Obtain unified tabular data and metadata, queried with MQL. The query should be of type List<Map<String, dynamic>>.

// import 'package:bson/bson.dart';

// List<Map<String, dynamic>>? _responseData;

 _viam = await Viam.withApiKey(
     dotenv.env['API_KEY_ID'] ?? '',
     dotenv.env['API_KEY'] ?? ''
 );
 final dataClient = _viam.dataClient;

 final query = BsonCodec.serialize({
  "\$match": {
     "location_id": "<YOUR-LOCATION-ID>",
  }
 });

 final sort = BsonCodec.serialize({
   "\$sort": {"time_requested": -1}
   sqlQuery
 });

 final limit = BsonCodec.serialize({"\$limit": 1});

 final pipeline = [query.byteList, sort.byteList, limit.byteList];
 _responseData = await dataClient.tabularDataByMql(
  "<YOUR-ORG-ID>",
  pipeline
 );

For more information, see Data Client API.

Implementation

Future<List<Map<String, dynamic>>> tabularDataByMql(String organizationId, dynamic query, {bool useRecentData = false}) async {
  List<Uint8List> binary;
  if (query is List<Map<String, dynamic>>) {
    binary = query.map((q) => BsonCodec.serialize(q).byteList).toList();
  } else if (query is List<Uint8List>) {
    binary = query;
  } else {
    throw TypeError();
  }
  final request = TabularDataByMQLRequest()
    ..organizationId = organizationId
    ..mqlBinary.addAll(binary)
    ..useRecentData = useRecentData;
  final response = await _dataClient.tabularDataByMQL(request);
  return response.rawData.map((e) => BsonCodec.deserialize(BsonBinary.from(e))).toList();
}