class Athena::ORM::EntityManagerFactory
inherits Reference
#
Creates entity managers on a database's connection pool, sharing their class metadata.
An entity manager tracks one unit of work, such as a request or a job, and isn't safe to share between fibers. Create the factory once and an entity manager per unit of work:
ORM = AORM::EntityManagerFactory.new DB.open(ENV["DATABASE_URL"])
ORM.with_entity_manager do |em|
em.find!(User, id).name = "George"
em.flush
end
The factory builds each entity's class metadata once, and shares it with every entity manager it creates.
Constructors#
.new(database : DB::Database, event_dispatcher : ACTR::EventDispatcher::Interface | Nil = nil)#
Creates a factory for entity managers on database.
Every entity manager it creates dispatches its flush and clear events to event_dispatcher, see AORM::EntityManager.new.
Methods#
#database : DB::Database#
Returns the database whose connection pool entity managers are created on.
#with_entity_manager : T#
Yields an entity manager on a connection checked out from the pool, and returns the block's value. Afterwards the entity manager is closed, any transaction the block left open is rolled back, and the connection goes back to the pool.