Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Loki
    • Database

Index

Properties

ENV: "NATIVESCRIPT" | "NODEJS" | "CORDOVA" | "BROWSER" | "NA"
addListener: <F>(eventName: string | string[], listener: F) => F

Type declaration

    • <F>(eventName: string | string[], listener: F): F
    • on(eventName, listener) - adds a listener to the queue of callbacks associated to an event

      Type parameters

      • F: (...args: any[]) => any

      Parameters

      • eventName: string | string[]

        the name(s) of the event(s) to listen to

      • listener: F

        callback function of listener to attach

      Returns F

      the index of the callback in the array of listeners for a particular event

asyncListeners: boolean
prop

asyncListeners - boolean determines whether or not the callbacks associated with each event should happen in an async fashion or not Default is false, which means events are synchronous

autosave: boolean
autosaveHandle: null | number
autosaveInterval: number
collections: Collection<any>[]
databaseVersion: number
engineVersion: number
events: {}
prop

events - a hashmap, with each property being an array of callbacks

Type declaration

  • [eventName: string]: ((...args: any[]) => any)[]
filename: string
name?: string
options: Partial<LokiConstructorOptions> & LokiConfigOptions & Partial<ThrottledSaveDrainOptions>
persistenceAdapter: undefined | null | LokiPersistenceAdapter
persistenceMethod: undefined | null | "fs" | "localStorage" | "memory" | "adapter"
save: (callback?: (err?: any) => void) => void

Type declaration

    • (callback?: (err?: any) => void): void
    • Handles manually saving to file system, local storage, or adapter (such as indexeddb) This method utilizes loki configuration options (if provided) to determine which persistence method to use, or environment detection (if configuration was not provided).

      If you are configured with autosave, you do not need to call this method yourself.

      example

      db.saveDatabase(function(err) { if (err) { console.log("error : " + err); } else { console.log("database saved."); } });

      Parameters

      • Optional callback: (err?: any) => void
          • (err?: any): void
          • Parameters

            • Optional err: any

            Returns void

      Returns void

throttledCallbacks: ((err?: any) => void)[]
throttledSavePending: boolean
throttledSaves: boolean
toJson: { (): string; (options: { serializationMethod?: "normal" | "pretty" }): string; (options: { serializationMethod: "destructured" }): string[]; (options?: { serializationMethod?: null | string }): string | string[]; (options?: { serializationMethod?: null | string }): string | string[] }

Type declaration

    • (): string
    • (options: { serializationMethod?: "normal" | "pretty" }): string
    • (options: { serializationMethod: "destructured" }): string[]
    • (options?: { serializationMethod?: null | string }): string | string[]
    • (options?: { serializationMethod?: null | string }): string | string[]
    • Serialize database to a string which can be loaded via {@link Loki#loadJSON}

      Returns string

      Stringified representation of the loki database.

    • Parameters

      • options: { serializationMethod?: "normal" | "pretty" }
        • Optional serializationMethod?: "normal" | "pretty"

      Returns string

    • Parameters

      • options: { serializationMethod: "destructured" }
        • serializationMethod: "destructured"

      Returns string[]

    • Parameters

      • Optional options: { serializationMethod?: null | string }
        • Optional serializationMethod?: null | string

      Returns string | string[]

    • Parameters

      • Optional options: { serializationMethod?: null | string }
        • Optional serializationMethod?: null | string

      Returns string | string[]

verbose: boolean

Methods

  • addCollection<F>(name: string, options?: Partial<CollectionOptions<F>>): Collection<F>
  • Adds a collection to the database.

    Type parameters

    • F: object = any

    Parameters

    • name: string

      name of collection to add

    • Optional options: Partial<CollectionOptions<F>>

      (optional) options to configure collection with.

    Returns Collection<F>

    a reference to the collection which was just added

  • autosaveClearFlags(): void
  • autosaveClearFlags - resets dirty flags on all collections. Called from saveDatabase() after db is saved.

    Returns void

  • autosaveDirty(): boolean
  • autosaveDirty - check whether any collections are 'dirty' meaning we need to save (entire) database

    Returns boolean

    true if database has changed since last autosave, false if not.

  • autosaveDisable(): void
  • autosaveDisable - stop the autosave interval timer.

    Returns void

  • autosaveEnable(options?: any, callback?: (err?: any) => void): void
  • autosaveEnable - begin a javascript interval to periodically save the database.

    Parameters

    • Optional options: any
    • Optional callback: (err?: any) => void
        • (err?: any): void
        • Parameters

          • Optional err: any

          Returns void

    Returns void

  • clearChanges(): void
  • (Changes API) : clears all the changes in all collections.

    Returns void

  • close(callback?: (err?: any) => void): void
  • Emits the close event. In autosave scenarios, if the database is dirty, this will save and disable timer. Does not actually destroy the db.

    Parameters

    • Optional callback: (err?: any) => void

      (Optional) if supplied will be registered with close event before emitting.

        • (err?: any): void
        • Parameters

          • Optional err: any

          Returns void

    Returns void

  • configureOptions(options?: Partial<LokiConfigOptions> & Partial<ThrottledSaveDrainOptions>, initialConfig?: boolean): void
  • Allows reconfiguring database options

    Parameters

    • Optional options: Partial<LokiConfigOptions> & Partial<ThrottledSaveDrainOptions>

      configuration options to apply to loki db object

    • Optional initialConfig: boolean

      (internal) true is passed when loki ctor is invoking

    Returns void

  • copy(options?: { removeNonSerializable?: boolean }): Loki
  • Copies 'this' database into a new Loki instance. Object references are shared to make lightweight.

    Parameters

    • Optional options: { removeNonSerializable?: boolean }

      apply or override collection level settings

      • Optional removeNonSerializable?: boolean

        nulls properties not safe for serialization.

    Returns Loki

  • deleteDatabase(callback: (err?: any, data?: any) => void): void
  • deleteDatabase(options?: null, callback?: (err?: any, data?: any) => void): void
  • deleteDatabase(options?: null | ((err?: any, data?: any) => void), callback?: (err?: any, data?: any) => void): void
  • Handles deleting a database from file system, local storage, or adapter (indexeddb) This method utilizes loki configuration options (if provided) to determine which persistence method to use, or environment detection (if configuration was not provided).

    Parameters

    • callback: (err?: any, data?: any) => void

      (Optional) user supplied async callback / error handler

        • (err?: any, data?: any): void
        • Parameters

          • Optional err: any
          • Optional data: any

          Returns void

    Returns void

  • Parameters

    • Optional options: null
    • Optional callback: (err?: any, data?: any) => void
        • (err?: any, data?: any): void
        • Parameters

          • Optional err: any
          • Optional data: any

          Returns void

    Returns void

  • Parameters

    • Optional options: null | ((err?: any, data?: any) => void)
    • Optional callback: (err?: any, data?: any) => void
        • (err?: any, data?: any): void
        • Parameters

          • Optional err: any
          • Optional data: any

          Returns void

    Returns void

  • deserializeCollection(destructuredSource: string | string[], options?: { delimited?: boolean; delimiter?: string; partitioned?: boolean }): any[]
  • Collection level utility function to deserializes a destructured collection.

    Parameters

    • destructuredSource: string | string[]

      destructured representation of collection to inflate

    • Optional options: { delimited?: boolean; delimiter?: string; partitioned?: boolean }
      • Optional delimited?: boolean
      • Optional delimiter?: string
      • Optional partitioned?: boolean

    Returns any[]

    an array of documents to attach to collection.data.

  • deserializeDestructured(destructuredSource: null | string | string[], options?: DeserializeOptions): any
  • Database level destructured JSON deserialization routine to minimize memory overhead. Internally, Loki supports destructuring via loki "serializationMethod' option and the optional LokiPartitioningAdapter class. It is also available if you wish to do your own structured persistence or data exchange.

    Parameters

    • destructuredSource: null | string | string[]

      destructured json or array to deserialize from

    • Optional options: DeserializeOptions

    Returns any

    An object representation of the deserialized database, not yet applied to 'this' db or document array

  • emit(eventName: string, data?: any, arg?: any): void
  • emit(eventName, data) - emits a particular event with the option of passing optional parameters which are going to be processed by the callback provided signatures match (i.e. if passing emit(event, arg0, arg1) the listener should take two parameters)

    Parameters

    • eventName: string

      the name of the event

    • Optional data: any

      optional object passed with the event

    • Optional arg: any

    Returns void

  • generateChangesNotification(arrayOfCollectionNames?: null | string[]): CollectionChange[]
  • (Changes API) : takes all the changes stored in each collection and creates a single array for the entire database. If an array of names of collections is passed then only the included collections will be tracked.

    see

    private method createChange() in Collection

    Parameters

    • Optional arrayOfCollectionNames: null | string[]

    Returns CollectionChange[]

    array of changes

  • getCollection<F>(collectionName: string): Collection<F>
  • Retrieves reference to a collection by name.

    Type parameters

    • F: object = any

    Parameters

    • collectionName: string

      name of collection to look up

    Returns Collection<F>

    Reference to collection in database by that name, or null if not found

  • getIndexedAdapter(): any
  • Returns any

  • getName(): string
  • Returns string

  • listCollections(): Collection<any>[]
  • Returns Collection<any>[]

  • loadCollection(collection: Collection<any>): void
  • Parameters

    • collection: Collection<any>

    Returns void

  • loadDatabase(options?: Partial<ThrottledSaveDrainOptions>, callback?: (err: any) => void): void
  • Handles manually loading from file system, local storage, or adapter (such as indexeddb) This method utilizes loki configuration options (if provided) to determine which persistence method to use, or environment detection (if configuration was not provided). To avoid contention with any throttledSaves, we will drain the save queue first.

    If you are configured with autosave, you do not need to call this method yourself.

    example

    db.loadDatabase({}, function(err) { if (err) { console.log("error : " + err); } else { console.log("database loaded."); } });

    Parameters

    • Optional options: Partial<ThrottledSaveDrainOptions>
    • Optional callback: (err: any) => void
        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

  • loadDatabaseInternal(options?: any, callback?: (err?: any, data?: any) => void): void
  • Internal load logic, decoupled from throttling/contention logic

    Parameters

    • Optional options: any
    • Optional callback: (err?: any, data?: any) => void
        • (err?: any, data?: any): void
        • Parameters

          • Optional err: any
          • Optional data: any

          Returns void

    Returns void

  • loadJSON(serializedDb: string, options?: { serializationMethod?: null | "normal" | "pretty" | "destructured" } & { retainDirtyFlags?: boolean; throttledSaves?: boolean }): void
  • Inflates a loki database from a serialized JSON string

    Parameters

    • serializedDb: string

      a serialized loki database string

    • Optional options: { serializationMethod?: null | "normal" | "pretty" | "destructured" } & { retainDirtyFlags?: boolean; throttledSaves?: boolean }

    Returns void

  • loadJSONObject(dbObject: { collections: Collection<any>[]; databaseVersion: number; name?: string; throttledSaves: boolean }, options?: { retainDirtyFlags?: boolean; throttledSaves?: boolean }): void
  • Inflates a loki database from a JS object

    Parameters

    • dbObject: { collections: Collection<any>[]; databaseVersion: number; name?: string; throttledSaves: boolean }

      a serialized loki database string

      • collections: Collection<any>[]
      • databaseVersion: number
      • Optional name?: string
      • throttledSaves: boolean
    • Optional options: { retainDirtyFlags?: boolean; throttledSaves?: boolean }

      apply or override collection level settings

      • [collName: string]: any | { inflate?: (src: object, dest?: object) => void; proto?: any }
      • Optional retainDirtyFlags?: boolean

        whether collection dirty flags will be preserved

      • Optional throttledSaves?: boolean

    Returns void

  • on<F>(eventName: string | string[], listener: F): F
  • on(eventName, listener) - adds a listener to the queue of callbacks associated to an event

    Type parameters

    • F: (...args: any[]) => any

    Parameters

    • eventName: string | string[]

      the name(s) of the event(s) to listen to

    • listener: F

      callback function of listener to attach

    Returns F

    the index of the callback in the array of listeners for a particular event

  • removeCollection(collectionName: string): void
  • Removes a collection from the database.

    Parameters

    • collectionName: string

      name of collection to remove

    Returns void

  • removeListener(eventName: string | string[], listener: (...args: any[]) => any): void
  • removeListener() - removes the listener at position 'index' from the event 'eventName'

    Parameters

    • eventName: string | string[]

      the name(s) of the event(s) which the listener is attached to

    • listener: (...args: any[]) => any

      the listener callback function to remove from emitter

        • (...args: any[]): any
        • Parameters

          • Rest ...args: any[]

          Returns any

    Returns void

  • renameCollection(oldName: string, newName: string): Collection<any>
  • Renames an existing loki collection

    Parameters

    • oldName: string

      name of collection to rename

    • newName: string

      new name of collection

    Returns Collection<any>

    reference to the newly renamed collection

  • saveDatabase(callback?: (err?: any) => void): void
  • Handles manually saving to file system, local storage, or adapter (such as indexeddb) This method utilizes loki configuration options (if provided) to determine which persistence method to use, or environment detection (if configuration was not provided).

    If you are configured with autosave, you do not need to call this method yourself.

    example

    db.saveDatabase(function(err) { if (err) { console.log("error : " + err); } else { console.log("database saved."); } });

    Parameters

    • Optional callback: (err?: any) => void
        • (err?: any): void
        • Parameters

          • Optional err: any

          Returns void

    Returns void

  • saveDatabaseInternal(callback?: (err: any) => void): void
  • Internal save logic, decoupled from save throttling logic

    Parameters

    • Optional callback: (err: any) => void
        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

  • serialize(): string
  • serialize(options: { serializationMethod?: "normal" | "pretty" }): string
  • serialize(options: { serializationMethod: "destructured" }): string[]
  • serialize(options?: { serializationMethod?: null | string }): string | string[]
  • serialize(options?: { serializationMethod?: null | string }): string | string[]
  • Serialize database to a string which can be loaded via {@link Loki#loadJSON}

    Returns string

    Stringified representation of the loki database.

  • Parameters

    • options: { serializationMethod?: "normal" | "pretty" }
      • Optional serializationMethod?: "normal" | "pretty"

    Returns string

  • Parameters

    • options: { serializationMethod: "destructured" }
      • serializationMethod: "destructured"

    Returns string[]

  • Parameters

    • Optional options: { serializationMethod?: null | string }
      • Optional serializationMethod?: null | string

    Returns string | string[]

  • Parameters

    • Optional options: { serializationMethod?: null | string }
      • Optional serializationMethod?: null | string

    Returns string | string[]

  • serializeChanges(collectionNamesArray?: string[]): string
  • (Changes API) - stringify changes for network transmission

    Parameters

    • Optional collectionNamesArray: string[]

    Returns string

    string representation of the changes

  • serializeCollection(options?: { collectionIndex?: number; delimited?: boolean; delimiter?: string }): string | string[]
  • Collection level utility method to serialize a collection in a 'destructured' format

    Parameters

    • Optional options: { collectionIndex?: number; delimited?: boolean; delimiter?: string }
      • Optional collectionIndex?: number
      • Optional delimited?: boolean
      • Optional delimiter?: string

    Returns string | string[]

    A custom, restructured aggregation of independent serializations for a single collection.

  • serializeDestructured(options?: { delimited?: boolean; delimiter?: string; partition?: number; partitioned?: boolean }): string | string[]
  • Database level destructured JSON serialization routine to allow alternate serialization methods. Internally, Loki supports destructuring via loki "serializationMethod' option and the optional LokiPartitioningAdapter class. It is also available if you wish to do your own structured persistence or data exchange.

    Parameters

    • Optional options: { delimited?: boolean; delimiter?: string; partition?: number; partitioned?: boolean }

      output format options for use externally to loki

      • Optional delimited?: boolean

        (default: true) whether subitems are delimited or subarrays

      • Optional delimiter?: string

        override default delimiter

      • Optional partition?: number

        can be used to only output an individual collection or db (-1)

      • Optional partitioned?: boolean

        (default: false) whether db and each collection are separate

    Returns string | string[]

    A custom, restructured aggregation of independent serializations.

  • serializeReplacer(key: string, value: any): any
  • serializeReplacer - used to prevent certain properties from being serialized

    Parameters

    • key: string
    • value: any

    Returns any

  • throttledSaveDrain(callback: (result?: boolean) => void, options?: Partial<ThrottledSaveDrainOptions>): void
  • Wait for throttledSaves to complete and invoke your callback when drained or duration is met.

    Parameters

    • callback: (result?: boolean) => void

      callback to fire when save queue is drained, it is passed a sucess parameter value

        • (result?: boolean): void
        • Parameters

          • Optional result: boolean

          Returns void

    • Optional options: Partial<ThrottledSaveDrainOptions>

    Returns void

Generated using TypeDoc