DatabaseTable class

Annotation for marking a Dart class as a database table.

This annotation is applied to Dart classes to indicate that they should be converted to PostgreSQL/Supabase database tables. It provides extensive configuration options for customizing the generated table.

Basic Usage:

@DatabaseTable()
class User {
  String? id;
  String email;
  DateTime? createdAt;
}

Advanced Usage:

@DatabaseTable(
  name: 'app_users',
  schema: 'auth',
  enableRLS: true,
  comment: 'Application users with authentication data',
  addTimestamps: true,
  policies: [
    RLSPolicy.authenticatedRead(),
    RLSPolicy.ownerWrite('user_id'),
  ],
)
class User { ... }
Annotations
  • @immutable

Constructors

DatabaseTable({String? name, String schema = 'public', bool enableRLS = true, String? comment, bool addTimestamps = true, List<RLSPolicy> policies = const [], List<DatabaseIndex> indexes = const [], List<TableConstraint> constraints = const [], String? tablespace, bool withOids = false, String? inheritFrom, PartitionStrategy? partitionBy, List<Validator> validationRules = const []})
Creates a database table annotation with the specified configuration.
const

Properties

addTimestamps → bool
Whether to automatically add created_at and updated_at timestamp columns.
final
comment → String?
Optional comment for the table.
final
constraints → List<TableConstraint>
List of table-level constraints.
final
enableRLS → bool
Whether to enable Row Level Security (RLS) on this table.
final
hashCode → int
The hash code for this object.
no setterinherited
indexes → List<DatabaseIndex>
List of indexes to create for this table.
final
inheritFrom → String?
Parent table to inherit from.
final
name → String?
The table name in the database.
final
partitionBy → PartitionStrategy?
Partitioning strategy for the table.
final
policies → List<RLSPolicy>
List of RLS policies to apply to this table.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
schema → String
The database schema name.
final
tablespace → String?
Custom tablespace for the table.
final
validationRules → List<Validator>
Custom validation rules for the table.
final
withOids → bool
Whether to create the table with OIDs.
final

Methods

getEffectiveName(String className) → String
Gets the effective table name (either specified name or generated from class name).
getFullyQualifiedName(String className) → String
Gets the fully qualified table name (schema.table).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
Returns a string representation of this table configuration.
override
validate() → List<String>
Validates the table configuration.

Operators

operator ==(Object other) → bool
The equality operator.
inherited