selectOnly method

Perform a SELECT query on the table or view, reading columns only.

Each entry has to belong to this table, and the rows come back as PostgrestPartialRows that are read through the same entries, so a column left out cannot be read by mistake:

final books = await client
    .table(Books.table)
    .selectOnly([Books.id, Books.title]);
final String title = books.first.read(Books.title);

An embedded relation is selected column by column, Books.author(Authors.name), or as a whole, Books.author.select(). Entries of one relation are sent as a single embed whatever their order in columns, so author(id) and author(name) become author(id,name), and the embedded rows are read through the relation:

final books = await client
    .table(Books.table)
    .selectOnly([
      Books.id,
      Books.author.select([Authors.id, Authors.name]),
    ]);
final String? author = books.first.read(Books.author)?.read(Authors.name);

PostgrestTable.allColumns selects every column next to embeds and aggregates, and PostgrestPartialRow.toRow converts such a row into Row.

columns needs at least one entry; use select for every column.

Implementation

PostgrestTypedFilterBuilder<Row, List<PostgrestPartialRow<Row>>> selectOnly(
  List<PostgrestSelectable<Row>> columns,
) => PostgrestTypedFilterBuilder._(
  _request(
    PostgrestTableOperation.select,
  ).copyWith(columns: _checkedSelections(columns, 'columns')),
  _executor,
  _partialRowsConverter(columns),
  table.rowFromJson,
);