Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DB

Database constructor containing all the initialised collections

Hierarchy

  • DB

Index

Constructors

constructor

  • new DB(name?: string, opts?: { backupProvider?: BackupProvider; eventHandlers?: EventHandlersType; storageEngine?: StorageProvider; useDynamicIndexes?: boolean }): DB
  • Construct a new in memory db with the provided collection references

    Parameters

    • name: string = ...

      Name of database

    • opts: { backupProvider?: BackupProvider; eventHandlers?: EventHandlersType; storageEngine?: StorageProvider; useDynamicIndexes?: boolean } = {}

      Options object to modify DB behaviour (mostly unused)

      • Optional backupProvider?: BackupProvider

        BackupProvider to save and restore documents/collections to and from

      • Optional eventHandlers?: EventHandlersType

        Map of plugins to apply to the database

      • Optional storageEngine?: StorageProvider

        Storage provider for document data

      • Optional useDynamicIndexes?: boolean

        Automatically generate dynamic indexes - link deeply nested content in a document to the root document to speed up future query results

    Returns DB

Properties

collections

collections: {} = {}

Type declaration

Readonly db_

db_: Debugger

Debugger variable

Readonly name

name: string = 'memsdb'

Key based object containing all the collections

options

options: { backupProvider: BackupProvider; useDynamicIndexes: boolean }

Type declaration

  • backupProvider: BackupProvider
  • useDynamicIndexes: boolean

Readonly storageEngine

storageEngine: StorageProvider

Methods

addCollection

  • Add a new collection to the DB. It won't replace a collection unless you specify to

    Parameters

    • collection: DBCollection

      Collection to add to the db

    • opts: AddCollectionOpts = ...

    Returns DBCollection

addEventHandler

  • Add an EventHandler class to the DB

    Parameters

    Returns void

backup

  • backup(): void
  • Backup collection data to the provided BackupProvider.

    Returns void

c

  • Return a specified collection by name

    Parameters

    • name: string

      Collection name to select

    Returns DBCollection

collection

  • Alias of this.c() - Returns a specified collection

    Parameters

    • name: string

      Name of collection to retrieve

    Returns DBCollection

deleteCollection

  • deleteCollection(name: string): DB
  • Delete a collection and all its documents

    Parameters

    • name: string

      Collection name to delete

    Returns DB

emitEvent

  • emitEvent(event: MemsDBEvent): void
  • Loop over the EventHandlers and emit the event to the provided function

    Parameters

    • event: MemsDBEvent

      Event to emit

    Returns void

emptyCollection

  • emptyCollection(name: string): DB
  • Empty out a collection, deleting the documents but leaving the collection structure intact

    Parameters

    • name: string

      Empty out a specified collection

    Returns DB

restore

  • restore(): void
  • Restore collection documents from a backup using the provided BackupProvider. This won't overwrite any documents

    Returns void

Generated using TypeDoc