Skip to content

struct Athena::ORM::Bundle
inherits Athena::DependencyInjection::AbstractBundle #

Integrates the ORM with the dependency injection component, such as within an Athena Framework application.

Require athena-orm/bundle to register the bundle, then configure the URL of the database:

require "athena"
require "athena-orm/bundle"

ADI.configure({
  orm: {
    url: ENV["DATABASE_URL"],
  },
})

Each AORM::EntityManagerInterface that's injected is the entity manager of the current unit of work, such as a request, see AORM::Bundle::Registry:

@[ADI::Register]
class UserController < ATH::Controller
  def initialize(@em : AORM::EntityManagerInterface); end

  @[ARTA::Get("/user/{id}")]
  def user(id : Int64) : User?
    @em.find User, id
  end
end