Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Database

Hierarchy

  • Database

Index

Constructors

constructor

Properties

Private currentRevision

currentRevision: DatabaseRevision

Current revision of the database. Incremented at every change in a table.

persistentStorage

persistentStorage: PersistentStorage

Persistent storage of the database. It is automatically saved and loaded by the database, but is publicly exposed and provide no special feature like revisions.

Private tables

tables: object

Tables of the database. The keys are the table names, and the values are the related DatabaseTable objects.

Type declaration

Static LOCAL_STORAGE_KEY

LOCAL_STORAGE_KEY: string = "sam-data"

Local storage key used to save the serialized database content.

Methods

Private clearLocalStorageData

  • clearLocalStorageData(): void
  • Clear any local storage field holding database data.

    Note: if the local storage is not available, nothing happen.

    Returns void

empty

  • empty(): void
  • Empty the database content (set to default values), and clear all data saved in the local storage.

    Returns void

getCurrentRevision

getItemClickLogs

getItemClickLogsCurrentIndex

  • Get the index where the next item click log would be inserted in the table.

    Note: this is also equal to the number of item click log entries.

    Returns TableEntryIndex

    The index of the next item click log entry.

getPageVisitLogs

getPageVisitLogsCurrentIndex

  • Get the index where the next page visit log would be inserted in the table.

    Note: this is also equal to the number of page visit log entries.

    Returns TableEntryIndex

    The index of the next page visit log entry.

Private init

  • init(): void

isLocalStorageDataAvailable

  • isLocalStorageDataAvailable(): boolean
  • Test whether some database data is available in the local storage.

    Returns boolean

    true if the local storage is available and the value for key Database.LOCAL_STORAGE_KEY is not null, false otherwise.

isRevisionUpToDate

  • Test whether the given revision is equal to the current one.

    Parameters

    Returns boolean

    true if the two revisions are equal, false otherwise.

Private loadFromLocalStorage

  • loadFromLocalStorage(): void
  • Load a JSON description database data from the local storage, unserialize it, and update internal fields with available data (see unpackDataFromJSON).

    Note: if the local storage is not available, nothing happen.

    Returns void

logItemClick

logPageVisit

Private onPageUnload

  • onPageUnload(): void
  • Page unload callback: save the database content in the local storage.

    Returns void

Private packDataToJSON

  • packDataToJSON(): string
  • Group all the data to save, and serialize it as a single JSON string.

    Note: the data must be natively compatible with JSON serialization, using JSON.stringify (e.g. it does not work with Maps).

    Returns string

    A JSON string representing the serialized data.

Private saveInLocalStorage

  • saveInLocalStorage(): void
  • Group and serialize the database data into a JSON description (see packDataToJSON), and save it in the local storage.

    Note: if the local storage is not available, nothing happen.

    Returns void

Private setContentToDefault

  • setContentToDefault(): void
  • Set or reset the database content to default values (empty content).

    Note: this does not affect any data stored in the local storage.

    Returns void

Private startListeningForPageUnload

  • startListeningForPageUnload(): void

Private unpackDataFromJSON

  • unpackDataFromJSON(json: string): void
  • Unserialize the given JSON string, which must represent grouped data (according to packDataToJSON protocol), and update all internal fields for which some data is available (i.e. non-undefined values). *

    Parameters

    • json: string

      A JSON string representing the serialized data.

    Returns void

Generated using TypeDoc