buildSelectWithNestedData method

SqlStatement buildSelectWithNestedData()

Builds an SQLite SqlStatement to select data from the primary table and its related tables, constructing a nested JSON structure similar to what Supabase PostgREST would return.

The resulting query will typically select a single column named jsobjects containing the JSON string or an array of JSON strings.

This is useful for querying a local SQLite mirror of Supabase data in a way that mimics the nested structure of PostgREST responses.

Returns an SqlStatement ready for execution. The WHERE, ORDER BY, LIMIT, and OFFSET clauses should be added to this statement by other builder methods before execution.

Implementation

SqlStatement buildSelectWithNestedData() {
  // Recursively build the JSON structure starting from this builder
  final String topLevelJsonString = _buildRecursiveJson(tableAlias, 0);

  // The final SQL will select this JSON structure.
  // The alias 'AS jsobjects' is NOT added here. It should be added by the
  // final query executor if needed, allowing this method to be used for subqueries.
  return SqlStatement(
    operationType: SqlOperationType.select,
    tableName: primaryTableName, // Base table for the main FROM clause
    selectColumns: topLevelJsonString, // The JSON result, without an alias
    fromAlias: tableAlias, // Alias for the main table in the FROM clause
    // Other parts like where, orderBy, limit, offset are typically added later
  );
}