CodeVetter · Repo Unpack · Extension points
SeaQL/sea-orm
The main extension mechanisms are Rust traits, derive attributes, callback factories, and entity registration. Tooling adds command enums and generation backends, while examples expose framework-specific route tables. Extensions should preserve the common connection boundary and account for optional features and synchronous parity.
- ConnectionTrait is the shared execution interface accepted by ORM methods, allowing pool, transaction, mock, and custom implementations to support the same mutation and select APIs; StreamTrait adds a separate associated stream contract.
- ProxyDatabaseTrait is the custom backend adapter contract for query and execute results, with overridable transaction/ping hooks; Database::connect_proxy accepts an Arc<Box<dyn ProxyDatabaseTrait>> and a dialect.
- ActiveModelBehavior provides new, before_save, after_save, before_delete, and after_delete hooks; save hooks receive the insert/update distinction, and before hooks can abort by returning DbErr.
- EntityRegistry uses inventory::collect and a re-exported submit macro; each registration carries module_path and a schema-info factory, and build_schema selects registrations through normalized module-prefix matching.
- MigrationTrait supplies up/down and transaction-policy hooks; MigratorTrait supplies the ordered boxed migration list and overridable tracking-table name, while run_cli_with_connection accepts a connection factory.
- Codegen changes plug into EntityFormat, EntityWriterContext, and format-specific writer branches; context supports custom model/enum/column derives, attributes, serialization policy, date/time representation, and schema names.
- ConnectOptions stores backend option and pool-option callbacks plus an after-connect callback; PostgreSQL applies these during pool construction, and query metrics expose elapsed time, statement, and failure state to an optional callback.
- Dynamic Entity::from_entity exports typed entity metadata into runtime columns and ModelType fields; application integrations add endpoints through Actix init registrations, the PostRpc method trait, or Rocket merged endpoint/documentation mounts.