bavard library
Main entry point for the Bavard ORM library.
Exposes the core Model, QueryBuilder, DatabaseManager, and relationship classes required to interact with the database using the Active Record pattern. Annotations for code generation and type casting definitions.
Classes
-
AttributeCast<
T, R> - Interface for defining custom attribute casting logic.
- BavardPivot
- Marks a Pivot class for code generation.
-
BelongsTo<
R extends Model> - Defines an inverse one-to-one or many-to-one relationship where the foreign key resides on the child model (the parent of this relation instance).
-
BelongsToMany<
R extends Model> - Manages many-to-many relationships via an intermediate pivot table.
- DatabaseAdapter
- Protocol for database drivers.
- DatabaseManager
- Singleton service locator for the active database connection.
- Fillable
- GenericPivot
- A default concrete implementation of Pivot for when no custom class is defined.
- Grammar
-
HasMany<
R extends Model> -
Defines a one-to-many relationship where the foreign key resides on the related model
R. -
HasManyThrough<
R extends Model, I extends Model> - Defines a distant one-to-many relationship linking a Parent to a Target via an Intermediate model.
-
HasOne<
R extends Model> -
Defines a one-to-one relationship where the foreign key resides on the related model
R. - Model
- Core Active Record implementation serving as the bridge between Dart objects and the DB.
-
MorphMany<
R extends Model> - Defines a polymorphic one-to-many relationship.
-
MorphOne<
R extends Model> - Defines a polymorphic one-to-one relationship.
-
MorphTo<
R extends Model> - Represents the inverse side of a polymorphic relationship (the child holding the keys).
-
MorphToMany<
R extends Model> - Defines a polymorphic many-to-many relationship.
- Pivot
- Represents a row in a Many-to-Many pivot table.
- PostgresGrammar
-
QueryBuilder<
T extends Model> - Fluent interface for constructing type-safe SQL queries and hydrating results into Model instances.
- RawExpression
-
Relation<
R extends Model> - Base class for all database relationships.
- Scope
- Interface for cross-cutting query constraints (e.g., SoftDeletes, Multi-tenancy).
- SQLiteGrammar
- TransactionContext
- Context object passed to transaction callbacks.
- Utils
- Helpers for ORM 'Convention over Configuration' naming resolution.
Enums
- OrmCastType
- Canonical mapping between schema type strings and Dart runtime types.
Mixins
- HasGlobalScopes
- Injects default query constraints (scopes) into the Model's query builder lifecycle.
- HasGuardsAttributes
- Implements Mass Assignment protection to secure models against unsafe data injection.
- HasSoftDeletes
-
Implements the "Soft Delete" pattern using a
deleted_attimestamp. - HasTimestamps
-
Automates the maintenance of audit timestamps (
created_at,updated_at) during persistence. - HasUuids
- Enforces client-side UUID generation for Primary Keys (UUID v4).
Extensions
- TypedQuery on T
-
Bridge to obtain a strongly-typed
QueryBuilder<T>from a Model instance. - TypedRelations on Model
- Helper extension to safely cast dynamic relation data.
Constants
- bavardPivot → const BavardPivot
- fillable → const Fillable
- Marks a Model class for code generation.
Typedefs
-
ScopeCallback
= void Function(QueryBuilder<
Model> builder)
Exceptions / Errors
- BavardException
- Base exception for all ORM-related errors.
- DatabaseNotInitializedException
- Thrown when attempting to use the database before initialization.
- InvalidQueryException
- Thrown when an invalid query structure is detected.
- MassAssignmentException
- Thrown when mass assignment protection blocks an attribute.
- ModelNotFoundException
- Thrown when a requested model cannot be found in the database.
- QueryException
- Thrown when a database query fails to execute.
- RelationNotFoundException
- Thrown when a relationship cannot be resolved.
- TransactionException
- Thrown when a database transaction fails.