Tables

Detailed guide on generated table and row classes for type-safe database access.

Supabase Codegen generates two main classes for each table:

  1. Table Class: Handles database operations (insert, query, update, delete).
  2. Row Class: Represents a typed record from that table.

Feature Overview

  • Typed Rows: Full IntelliSense for all column names and types.
  • Null Safety: Correctly reflects database nullability.
  • Default Values: Field getters fallback to database default values.
  • CRUD Operations: High-level methods for common operations.

Examples

Table and Row Definition

Usage: CRUD Operations

final profilesTable = ProfilesTable();

// INSERT
final newProfile = await profilesTable.insert({
  ProfilesRow.emailField: 'hello@world.com',
  ProfilesRow.bioField: 'Software Engineer',
});

// QUERY
final profile = await profilesTable.querySingleRow(
  queryFn: (q) => q.eq(ProfilesRow.emailField, 'hello@world.com'),
);

// UPDATE
await profilesTable.update(
  row: profile.copyWith(bio: 'Senior Software Engineer'),
  matchingRows: (q) => q.eq(ProfilesRow.idField, profile.id),
);

Use copyWith to easily create updated versions of your row objects before calling update.