Model<TTable extends Table, TModel> class abstract

Base class for ORM models providing Active Record pattern

This abstract class provides Laravel-like methods for database operations. Subclasses must implement the abstract methods to define their table operations.

Example:

class User extends Model<UsersTable, User> {
  final int id;
  final String name;
  final String email;

  User({required this.id, required this.name, required this.email});

  @override
  UsersCompanion toCompanion() {
    return UsersCompanion(
      id: Value(id),
      name: Value(name),
      email: Value(email),
    );
  }

  @override
  int get primaryKey => id;
}

Constructors

Model()

Properties

database DatabaseConnectionUser
Get the database instance
no setter
hashCode int
The hash code for this object.
no setterinherited
primaryKey → dynamic
Get the primary key value
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
table TableInfo<TTable, dynamic>
Get the table for this model
no setter

Methods

delete() Future<void>
Delete the model
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
save() Future<void>
Save the model (insert if new, update if exists)
toCompanion() UpdateCompanion
Convert model to a Drift companion for inserts/updates
toString() String
A string representation of this object.
inherited

Operators

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