Class AirshipDataStoreService

The Data Store provides simple key/value persistent storage.

The data store provides durable storage that can be accessed from any game server. Data access is slower than the Cache Store, but the data will never expire.

The Data Store is good for things like user profiles or unlocks. If you want to keep track of user statistics or build tradable inventory, check out the Leaderboard and PlatformInventory systems.

Methods

  • Checks that the key is valid

    Parameters

    • key: string

    Returns void

  • Deletes the data associated with the given key.

    Type Parameters

    • T extends object

    Parameters

    • key: string

      The key to use. Keys must be alphanumeric and may include the following symbols: _-.:

    Returns Promise<undefined | T>

    The data that was deleted. If no data was deleted, nothing will be returned.

  • Works similarly to GetAndSet, but allows you to delete a key based on the key's data. If the callback returns true, the key will be deleted only if it has not changed. If the callback returns false, this function will return the current data value of the key. If the key is already unset, the function will return success with no data.

    The callback function will not be called if the key has no associated data.

    Type Parameters

    • T extends object

    Parameters

    • key: string

      The key to use. Keys must be alphanumeric and may include the following symbols: _-.:

    • callback: ((record) => boolean | Promise<boolean>)

      The function that will be called to determine if the value should be deleted. Returning true will delete the key.

        • (record): boolean | Promise<boolean>
        • Parameters

          • record: T

          Returns boolean | Promise<boolean>

    Returns Promise<undefined | T>

    The data that was deleted. If no data was deleted, nothing will be returned.

  • Allows you to update data for a key only if the data has not been changed since it was retrieved. This is good for keys which may be modified across different servers and you want to make sure that you are always operating on the most up to date data. This function is also useful when multiple servers may attempt to set the initial data for a key. It will ensure that only one set operation succeeds in writing the intial data.

    This function works by first retrieving the data associated with a key, then passing that data to the provided callback. The return value of the provided callback will be used as the new data for the key. If a change has been made to the data associated with the key between the get operation and the set operation, this function will fail with a conflict error.

    If no data is associated with the key initially, the callback will be provided no data, and the return value will be associated with the provided key. If data was associated with the key between the get operation and the set operation, this function will fail with a conflict error.

    Returning no data from the callback (undefined) will abort the update and no data will be changed.

    Type Parameters

    • T extends object

    Parameters

    • key: string

      The key to use. Keys must be alphanumeric and may include the following symbols: _-.:

    • callback: ((record?) => undefined | T | Promise<undefined | T>)

      The function that will be called to retrieve the new data value.

        • (record?): undefined | T | Promise<undefined | T>
        • Parameters

          • Optional record: T

          Returns undefined | T | Promise<undefined | T>

    Returns Promise<undefined | T>

    The data that was associated with the provided key.

  • Gets the data associated with the given key.

    Type Parameters

    • T extends object

    Parameters

    • key: string

      The key to use. Keys must be alphanumeric and may include the following symbols: _-.:

    Returns Promise<undefined | T>

    The data associated with the provided key. If no data is found, nothing is returned.

  • Returns information about the current lock holder for a given key. You can use this information to decide if you wish to steal a lock.

    Parameters

    • key: string

      The key to get lock information for.

    Returns Promise<IsDataLocked>

    The lock information.

  • Locks a data store key so that only the server that locked the key can write to it. The lock mode can be specified to allow reads from other servers on locked keys. Locks time out after 24 hours.

    This function does not perform any additional actions in attempt to aquire the lock.

    Parameters

    • key: string

      The key to lock.

    • mode: BlobLockMode = "READ_WRITE"

      The mode to lock the key with. Defaults to ReadWrite which disables both reading and writing on all other servers.

    • Optional stealFromOwnerId: string

      Steals the lock from this ownerId if the key is already locked.

    Returns Promise<boolean>

    True if the key was successfully locked to this server. False otherwise.

  • Locks a data store key so that only the server that locked the key can write to it. The lock mode can be specified to allow reads from other servers on locked keys. Locks time out after 24 hours.

    This function performs additional checks and attempts to steal the lock if it can be stolen safely.

    A lock can be stolen safely if the server that owns the lock is offline.

    Parameters

    • key: string

      The key to lock.

    • mode: BlobLockMode = "READ_WRITE"

      The mode to lock the key with. Defaults to ReadWrite which disables both reading and writing on all other servers.

    Returns Promise<boolean>

    True if the key was successfully locked to this server. False otherwise.

  • Sets the data for the given key.

    Type Parameters

    • T extends object

    Parameters

    • key: string

      The key to use. Keys must be alphanumeric and may include the following symbols: _-.:

    • data: T

      The data to associate with the provided key.

    Returns Promise<T>

    The data that was associated with the provided key.

  • Unlocks a data store key so that all servers can read and write the key. If the current game server does not own the lock, this operation will fail, unless you steal the lock by providing the current ownerId of the lock.

    Parameters

    • key: string

      The key you wish to unlock.

    • Optional stealFromOwnerId: string

      The ownerId of the current lock holder. Only provide this parameter if you want to steal the lock.

    Returns Promise<boolean>

    True if the key was successfully unlocked. False otherwise.