Skip to content

v5.11.0

Compare
Choose a tag to compare
@notheotherben notheotherben released this 31 Aug 16:00
· 405 commits to main since this release

Added

Description

Connection hooks allow you to implement custom logic controlling the way in which Iridium's Core both creates its database connection, as well as being notified once the connection has been established. This comes in very handy for implementing automatic index generation for your models.

Here's an example of how one would go about automatically setting up your indexes for a model when the database connection is established. It is important to be aware that, unless your indexes are set to { background: true }, this operation will block the completion of the Iridium.Core.connect method - and generating indexes on a large database can take some time...

class MyCore extends Iridium.Core {

    MyModel = new Iridium.Model<MyModelDocument, MyModelInstance>(this, MyModelInstance);

    protected onConnected() {
        return this.MyModel.ensureIndexes();
    }

}