Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Core

The Iridium Core, responsible for managing the connection to the database as well as any plugins you are making use of.

Generally you will subclass this to provide your own custom core with the models you make use of within your application.

Hierarchy

  • Core

Index

Constructors

constructor

  • Creates a new Iridium Core instance connected to the specified MongoDB instance

    constructs

    Core

    Parameters

    • config: Configuration

      The config object defining the database to connect to

    Returns Core

  • Creates a new Iridium Core instance connected to the specified MongoDB instance

    constructs

    Core

    Parameters

    • uri: string
    • Optional config: Configuration

      The config object defining the database to connect to

    Returns Core

Properties

Private _cache

_cache: Cache = new NoOpCache()

Private _config

_config: Configuration | undefined

Private _connectPromise

_connectPromise: Promise<MongoClient> | undefined

Private _connection

_connection: MongoClient | undefined

Private _dbName

_dbName: string

Private _plugins

_plugins: Plugin[] = []

Private _url

_url: string

Accessors

cache

  • get cache(): Cache
  • set cache(value: Cache): void
  • Gets the cache used to store objects retrieved from the database for performance reasons

    Returns Cache

  • Gets the cache used to store objects retrieved from the database for performance reasons

    Parameters

    Returns void

connection

  • get connection(): MongoClient
  • Gets the currently active database connection for this Iridium Core.

    Returns MongoClient

db

  • get db(): Db
  • Gets the database that this Iridium core is connected to

    Returns Db

dbName

  • get dbName(): string
  • Gets the name of the database that this Iridium core is connected to

    Returns string

plugins

settings

  • Gets the configuration specified in the construction of this Iridium Core.

    Returns Configuration | undefined

url

  • get url(): string
  • Gets the URL used to connect to MongoDB

    Returns string

Methods

close

  • close(callback?: Callback<this>): Promise<this>
  • Closes the active database connection

    type

    {Promise}

    Parameters

    Returns Promise<this>

connect

  • connect(callback?: Callback<this>): Promise<this>
  • Connects to the database server specified in the provided configuration

    Parameters

    Returns Promise<this>

express

  • Provides an express middleware which can be used to set the req.db property to the current Iridium instance.

    Returns ExpressMiddleware

Private mongoConnectAsyc

  • mongoConnectAsyc(url: string, opts: MongoClientOptions): Promise<MongoClient>
  • Parameters

    • url: string
    • opts: MongoClientOptions

    Returns Promise<MongoClient>

Protected onConnected

  • onConnected(): PromiseLike<void>
  • A method which is called once a database connection has been established and accepted by Iridium

    In subclassed Iridium cores this method can be overridden to perform tasks whenever a connection to the database has been established - such as setting up indexes for your collections or seeding the database.

    Returns PromiseLike<void>

Protected onConnecting

  • onConnecting(connection: MongoClient): PromiseLike<MongoClient>
  • A method which is called whenever a new connection is made to the database.

    Parameters

    • connection: MongoClient

      The underlying MongoDB connection which was created, you can modify or replace this if you wish.

    Returns PromiseLike<MongoClient>

    A promise for the connection, allowing you to perform any asynchronous initialization required by your application.

    In subclassed Iridium Cores this method can be overridden to manipulate the properties of the underlying MongoDB connection object, such as authenticating. Until this method resolves a connection object, Iridium will be unable to execute any queries. If you wish to run Iridium queries then look at the onConnected method.

Private parseDbName

  • parseDbName(urlStr: string): string
  • Parses the name of a DB from a URL string

    Parameters

    • urlStr: string

      The url string whose path component is the name of the DB

    Returns string

register

  • register(plugin: Plugin): this
  • Registers a new plugin with this Iridium Core

    Parameters

    • plugin: Plugin

      The plugin to register with this Iridium Core

    Returns this

Generated using TypeDoc