module
Marten::DB::Router
Overview
Database routing helpers.
This module provides the framework-level API used to consult the configured database routers when resolving
connections and permissions. Routers are configured via the database_routers setting and are consulted in
order; the first non-nil opinion wins.
Defined in:
marten/db/router.crmarten/db/router/base.cr
marten/db/router/hints.cr
Class Method Summary
-
.allow_migrate?(db : String, app_label : String, model_name : String | Nil = nil, hints : Hints = Hints.new) : Bool
Returns whether a migration should be applied to the given database.
-
.allow_relation?(obj1 : Model, obj2 : Model, hints : Hints = Hints.new) : Bool
Returns whether a relation between the two model instances should be allowed.
-
.db_for_read(model : Model.class, hints : Hints = Hints.new) : String | Nil
Returns the database alias to use for read operations involving the given model.
-
.db_for_write(model : Model.class, hints : Hints = Hints.new) : String | Nil
Returns the database alias to use for write operations involving the given model.
Class Method Detail
Returns whether a migration should be applied to the given database.
Configured routers are consulted in order. The first non-nil result is returned. If all routers abstain, the
migration is allowed.
Returns whether a relation between the two model instances should be allowed.
Configured routers are consulted in order. The first non-nil result is returned. If all routers abstain, the
relation is allowed.
Returns the database alias to use for read operations involving the given model.
Configured routers are consulted in order. The first non-nil result is returned. If all routers abstain,
nil is returned and the caller should fall back to the default database.
Returns the database alias to use for write operations involving the given model.
Configured routers are consulted in order. The first non-nil result is returned. If all routers abstain,
nil is returned and the caller should fall back to the default database.