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.cr
marten/db/router/base.cr
marten/db/router/hints.cr

Class Method Summary

Class Method Detail

def self.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.

Configured routers are consulted in order. The first non-nil result is returned. If all routers abstain, the migration is allowed.


[View source]
def self.allow_relation?(obj1 : Model, obj2 : Model, hints : Hints = Hints.new) : Bool #

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.


[View source]
def self.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.

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.


[View source]
def self.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.

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.


[View source]